ab是Apache自带的HTTP压力测试工具,全称是ApacheBench,同微软的WAST、惠普的LoadRunner、QALoad等比起来,它要方便易用得多
ab是Apache的一个安装组件,所以需要下载Apache安装后才能使用,该命令位于Apache安装目录下的bin文件夹中
ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求
ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求

ab不像LR那么强大,但它足够轻便,若只是在开发过程中想检查一下某个模块的响应情况,或者做一些场景比较简单的测试,ab是个不错的选择
至少不用花费很多时间去学习LR中的那些复杂的功能,就更别说那License的价格了

下面简单介绍下它的用法

查询版本:[ab -V](注意这里是大写的V)

  1. [www.linuxidc.com @ www.linuxidc.com-RHEL63 ~]$ ab -V 
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $> 
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  4. Licensed to The Apache Software Foundation, http://www.apache.org/ 

查询参数:[ab -v](注意这里是小写的v)

  1. [www.linuxidc.com @ www.linuxidc.com-RHEL63 ~]$ ab -v 
  2. ab: option requires an argument -- v 
  3. ab: wrong number of arguments 
  4. Usage: ab [options] [http[s]://]hostname[:port]/path  
  5. Options are: 
  6.     //测试会话中所执行的请求个数,默认仅执行一个请求  
  7.     -n requests     Number of requests to perform 
  8.     //一次产生的请求个数,即同一时间发出多少个请求,默认为一次一个  
  9.     -c concurrency  Number of multiple requests to make 
  10.     //测试所进行的最大秒数,默认为无时间限制....其内部隐含值是[-n 50000],它可以使对服务器的测试限制在一个固定的总时间以内  
  11.     -t timelimit    Seconds to max. wait for responses 
  12.     -b windowsize   Size of TCP send/receive buffer, in bytes 
  13.     //包含了需要POST的数据的文件  
  14.     -p postfile     File containing data to POST. Remember also to set -T 
  15.     -u putfile      File containing data to PUT. Remember also to set -T 
  16.     //POST数据所使用的Content-type头信息  
  17.     -T content-type Content-type header for POSTing, eg. 
  18.                     'application/x-www-form-urlencoded' 
  19.                     Default is 'text/plain' 
  20.     //设置显示信息的详细程度,4或更大值会显示头信息,3或更大值可以显示响应码(404,200等),2或更大值可以显示警告和其他信息  
  21.     -v verbosity    How much troubleshooting info to print 
  22.     //以HTML表格的形式输出结果,默认是白色背景的两列宽度的一张表  
  23.     -w              Print out results in HTML tables 
  24.     //执行HEAD请求,而不是GET  
  25.     -i              Use HEAD instead of GET 
  26.     //设置<table>属性的字符串,此属性被填入<table 这里>  
  27.     -x attributes   String to insert as table attributes 
  28.     //设置<tr>属性的字符串  
  29.     -y attributes   String to insert as tr attributes 
  30.     //设置<td>属性的字符串  
  31.     -z attributes   String to insert as td or th attributes 
  32.     //对请求附加一个Cookie行,其典型形式是name=value的参数对,此参数可以重复  
  33.     -C attribute    Add cookie, eg. 'Apache=1234. (repeatable) 
  34.     //对请求附加额外的头信息,此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对(如"Accept-Encoding: zip/zop;8bit")  
  35.     -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip' 
  36.                     Inserted after all normal header lines. (repeatable) 
  37.     //HTTP验证,用冒号:分隔传递用户名及密码  
  38.     -A attribute    Add Basic WWW Authentication, the attributes 
  39.                     are a colon separated username and password. 
  40.     //对一个中转代理提供BASIC认证信任,用户名和密码由一个冒号:隔开,并以base64编码形式发送  
  41.     //无论服务器是否需要(即是否发送了401认证需求代码),此字符串都会被发送  
  42.     -P attribute    Add Basic Proxy Authentication, the attributes 
  43.                     are a colon separated username and password. 
  44.     //对请求使用代理服务器  
  45.     -X proxy:port   Proxyserver and port number to use 
  46.     //显示版本号并退出  
  47.     -V              Print version number and exit 
  48.     //启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求,默认为不启用KeepAlive功能  
  49.     -k              Use HTTP KeepAlive feature 
  50.     //不显示"percentage served within XX [ms] table"的消息(为以前的版本提供支持)  
  51.     -d              Do not show percentiles served table. 
  52.     //不显示中值和标准背离值,且均值和中值为标准背离值的1到2倍时,也不显示警告或出错信息,默认会显示最小值/均值/最大值等(为以前的版本提供支持)  
  53.     -S              Do not show confidence estimators and warnings. 
  54.     //把所有测试结果写入一个'gnuplot'或者TSV(以Tab分隔的)文件  
  55.     //此文件可以方便地导入到Gnuplot,IDL,Mathematica,Igor甚至Excel中,其中的第一行为标题  
  56.     -g filename     Output collected data to gnuplot format file. 
  57.     //产生一个以逗号分隔的(CSV)文件,其中包含了处理每个相应百分比的请求所需要(从1%到100%)的相应百分比的(以微妙为单位)时间  
  58.     //由于这种格式已经"二进制化",所以比'gnuplot'格式更有用  
  59.     -e filename     Output CSV file with percentages served 
  60.     -r              Don't exit on socket receive errors. 
  61.     //显示使用方法  
  62.     -h              Display usage information (this message) 
  63.     -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers) 
  64.     -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)