Apache的压力测试工具ab

来源:互联网 发布:java有没有goto 编辑:程序博客网 时间:2024/04/19 15:39
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)

[java] view plaincopyprint?
  1. [Jadyer@Jadyer-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)

[java] view plaincopyprint?
  1. [Jadyer@Jadyer-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)  

测试网站:[ab -n 1000 -c 10 http://192.168.8.35:9000/noCardNoPasswordSign]

-n表示总共发送的请求数
-c表示每次并发的请求数
使用ab测试时,其支持的最大并发数是没有限制的,但实际值要取决于Linux允许每个进程打开的最大文件数,即[ulimit -n]

[java] view plaincopyprint?
  1. [Jadyer@Jadyer-RHEL63 ~]$ ab -n 1000 -c 10 https://epay.10010.com/  
  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/  
  5.   
  6. Benchmarking epay.10010.com (be patient)  
  7. Completed 100 requests  
  8. Completed 200 requests  
  9. Completed 300 requests  
  10. Completed 400 requests  
  11. Completed 500 requests  
  12. Completed 600 requests  
  13. Completed 700 requests  
  14. Completed 800 requests  
  15. Completed 900 requests  
  16. Completed 1000 requests  
  17. Finished 1000 requests  
  18.   
  19.   
  20. //被测试Web服务软件名称,它来自于HTTP响应数据的头信息(Apache-Coyote/1.1也就是Tomcat)  
  21. Server Software:        Apache-Coyote/1.1  
  22. //服务器主机名,即请求的URL中的主机部分名称  
  23. Server Hostname:        epay.10010.com  
  24. //被测试Web服务器软件的监听端口  
  25. Server Port:            443  
  26. SSL/TLS Protocol:       TLSv1/SSLv3,DHE-RSA-AES256-SHA,2048,256  
  27.   
  28. //请求URL的绝问文件路径,即请求的资源  
  29. Document Path:          /  
  30. //HTTP响应正文的长度,不包括响应头,即减去了Total transferred中的HTML响应数据中头信息的长度  
  31. Document Length:        0 bytes  
  32.   
  33. //并发数(-c属性来设置)  
  34. Concurrency Level:      10  
  35. //执行完所有的请求所花费的时间,即整个测试持续的时间  
  36. Time taken for tests:   26.121 seconds  
  37. //完成的请求数量  
  38. Complete requests:      1000  
  39. //失败的请求数量  
  40. Failed requests:        0  
  41. Write errors:           0  
  42. Non-2xx responses:      1001  
  43. //整个场景中的网络传输量,即所有请求的响应数据的总和,包含头信息和正文长度  
  44. Total transferred:      299299 bytes  
  45. //整个场景中的HTML内容传输量,即所有请求中响应数据的正文长度,不包含头信息的长度  
  46. HTML transferred:       0 bytes  
  47. //吞吐率:即每秒处理的请求数,相当于LR中的每秒事务数,括号中的mean表示这是一个平均值,其值为Complete requests/Time taken for tests  
  48. Requests per second:    38.28 [#/sec] (mean)  
  49. //平均请求等待的时间:相当于LR中的平均事务响应时间,其值为Time taken for tests/(Complete requests/Concurrency Level)  
  50. Time per request:       261.206 [ms] (mean)  
  51. //服务器平均请求处理的时间,即每个请求实际运行时间的平均值,其值为Time per request/Concurrency Level  
  52. Time per request:       26.121 [ms] (mean, across all concurrent requests)  
  53. //平均每秒网络上的流量,即这些请求在单位内从服务器获取的数据长度,其值为(Total transferred/Time taken for tests/)1024  
  54. //这个统计选项可以很好的说明服务器在处理能力达到极限时其出口带宽的需求量  
  55. //可以帮助排除是否存在网络流量过大导致响应时间延长的问题  
  56. Transfer rate:          11.19 [Kbytes/sec] received  
  57.   
  58. //网络上消耗的时间的分解,各项数据的具体算法还不是很清楚  
  59. Connection Times (ms)  
  60.               min  mean[+/-sd] median   max  
  61. Connect:       85  222 101.0    205    1224  
  62. Processing:    12   38  23.4     34     151  
  63. Waiting:       12   37  23.5     33     151  
  64. Total:        144  259 100.9    244    1268  
  65.   
  66. //整个场景中所有请求的响应情况,在场景中每个请求都有一个响应时间  
  67. //下面结果表明,50%的用户响应时间(即请求处理时间,这里处理时间是指Time per request)小于244毫秒  
  68. //66%的用户响应时间小于252毫秒,而最大的响应时间小于1268毫秒  
  69. //对于并发请求,实际上CPU并不是同时处理的,而是按照每个请求获得的时间片而逐个轮转处理的  
  70. //所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数  
  71. Percentage of the requests served within a certain time (ms)  
  72.   50%    244  
  73.   66%    252  
  74.   75%    254  
  75.   80%    255  
  76.   90%    260  
  77.   95%    481  
  78.   98%    665  
  79.   99%    686  
  80.  100%   1268 (longest request)  

获取网站信息

[java] view plaincopyprint?
  1. [Jadyer@Jadyer-RHEL63 ~]$ curl -Is https://epay.10010.com/  
  2. HTTP/1.1 302 Moved Temporarily  
  3. Date: Tue, 06 Nov 2012 17:52:13 GMT  
  4. Server: Apache-Coyote/1.1  
  5. Location: http://epay.10010.com/404.jsp  
  6. Content-Type: text/vnd.wap.wml;chartset=gbk;charset=GBK  
  7. Set-Cookie: JSESSIONID=9DDBCA78C7FEF4ABECD070E744CE926C; Path=/  
原创粉丝点击