ab是Apache自带的HTTP压力测试工具,全称是
ApacheBench
,同微软的WAST、惠普的LoadRunner、QALoad等比起来,它要方便易用得多
ab是Apache的一个安装组件,所以需要下载Apache安装后才能使用,该命令位于Apache安装目录下的bin文件夹中
ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求
ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求
ab不像LR那么强大,但它足够轻便,若只是在开发过程中想检查一下某个模块的响应情况,或者做一些场景比较简单的测试,ab是个不错的选择
查询参数:[ab -v](注意这里是小写的v)
测试网站:[ab -n 1000 -c 10 http://192.168.8.35:9000/noCardNoPasswordSign]
获取网站信息
ab是Apache的一个安装组件,所以需要下载Apache安装后才能使用,该命令位于Apache安装目录下的bin文件夹中
ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求
ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求
ab不像LR那么强大,但它足够轻便,若只是在开发过程中想检查一下某个模块的响应情况,或者做一些场景比较简单的测试,ab是个不错的选择
至少不用花费很多时间去学习LR中的那些复杂的功能,就更别说那License的价格了
下面简单介绍下它的用法
查询版本:[ab -V](注意这里是大写的V)
- [Jadyer@Jadyer-RHEL63 ~]$ ab -V
- This is ApacheBench, Version 2.3 <$Revision: 655654 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
查询参数:[ab -v](注意这里是小写的v)
- [Jadyer@Jadyer-RHEL63 ~]$ ab -v
- ab: option requires an argument -- v
- ab: wrong number of arguments
- Usage: ab [options] [http[s]://]hostname[:port]/path
- Options are:
- //测试会话中所执行的请求个数,默认仅执行一个请求
- -n requests Number of requests to perform
- //一次产生的请求个数,即同一时间发出多少个请求,默认为一次一个
- -c concurrency Number of multiple requests to make
- //测试所进行的最大秒数,默认为无时间限制....其内部隐含值是[-n 50000],它可以使对服务器的测试限制在一个固定的总时间以内
- -t timelimit Seconds to max. wait for responses
- -b windowsize Size of TCP send/receive buffer, in bytes
- //包含了需要POST的数据的文件
- -p postfile File containing data to POST. Remember also to set -T
- -u putfile File containing data to PUT. Remember also to set -T
- //POST数据所使用的Content-type头信息
- -T content-type Content-type header for POSTing, eg.
- 'application/x-www-form-urlencoded'
- Default is 'text/plain'
- //设置显示信息的详细程度,4或更大值会显示头信息,3或更大值可以显示响应码(404,200等),2或更大值可以显示警告和其他信息
- -v verbosity How much troubleshooting info to print
- //以HTML表格的形式输出结果,默认是白色背景的两列宽度的一张表
- -w Print out results in HTML tables
- //执行HEAD请求,而不是GET
- -i Use HEAD instead of GET
- //设置<table>属性的字符串,此属性被填入<table 这里>
- -x attributes String to insert as table attributes
- //设置<tr>属性的字符串
- -y attributes String to insert as tr attributes
- //设置<td>属性的字符串
- -z attributes String to insert as td or th attributes
- //对请求附加一个Cookie行,其典型形式是name=value的参数对,此参数可以重复
- -C attribute Add cookie, eg. 'Apache=1234. (repeatable)
- //对请求附加额外的头信息,此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对(如"Accept-Encoding: zip/zop;8bit")
- -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
- Inserted after all normal header lines. (repeatable)
- //HTTP验证,用冒号:分隔传递用户名及密码
- -A attribute Add Basic WWW Authentication, the attributes
- are a colon separated username and password.
- //对一个中转代理提供BASIC认证信任,用户名和密码由一个冒号:隔开,并以base64编码形式发送
- //无论服务器是否需要(即是否发送了401认证需求代码),此字符串都会被发送
- -P attribute Add Basic Proxy Authentication, the attributes
- are a colon separated username and password.
- //对请求使用代理服务器
- -X proxy:port Proxyserver and port number to use
- //显示版本号并退出
- -V Print version number and exit
- //启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求,默认为不启用KeepAlive功能
- -k Use HTTP KeepAlive feature
- //不显示"percentage served within XX [ms] table"的消息(为以前的版本提供支持)
- -d Do not show percentiles served table.
- //不显示中值和标准背离值,且均值和中值为标准背离值的1到2倍时,也不显示警告或出错信息,默认会显示最小值/均值/最大值等(为以前的版本提供支持)
- -S Do not show confidence estimators and warnings.
- //把所有测试结果写入一个'gnuplot'或者TSV(以Tab分隔的)文件
- //此文件可以方便地导入到Gnuplot,IDL,Mathematica,Igor甚至Excel中,其中的第一行为标题
- -g filename Output collected data to gnuplot format file.
- //产生一个以逗号分隔的(CSV)文件,其中包含了处理每个相应百分比的请求所需要(从1%到100%)的相应百分比的(以微妙为单位)时间
- //由于这种格式已经"二进制化",所以比'gnuplot'格式更有用
- -e filename Output CSV file with percentages served
- -r Don't exit on socket receive errors.
- //显示使用方法
- -h Display usage information (this message)
- -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
- -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]
- [Jadyer@Jadyer-RHEL63 ~]$ ab -n 1000 -c 10 https://epay.10010.com/
- This is ApacheBench, Version 2.3 <$Revision: 655654 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
- Benchmarking epay.10010.com (be patient)
- Completed 100 requests
- Completed 200 requests
- Completed 300 requests
- Completed 400 requests
- Completed 500 requests
- Completed 600 requests
- Completed 700 requests
- Completed 800 requests
- Completed 900 requests
- Completed 1000 requests
- Finished 1000 requests
- //被测试Web服务软件名称,它来自于HTTP响应数据的头信息(Apache-Coyote/1.1也就是Tomcat)
- Server Software: Apache-Coyote/1.1
- //服务器主机名,即请求的URL中的主机部分名称
- Server Hostname: epay.10010.com
- //被测试Web服务器软件的监听端口
- Server Port: 443
- SSL/TLS Protocol: TLSv1/SSLv3,DHE-RSA-AES256-SHA,2048,256
- //请求URL的绝问文件路径,即请求的资源
- Document Path: /
- //HTTP响应正文的长度,不包括响应头,即减去了Total transferred中的HTML响应数据中头信息的长度
- Document Length: 0 bytes
- //并发数(-c属性来设置)
- Concurrency Level: 10
- //执行完所有的请求所花费的时间,即整个测试持续的时间
- Time taken for tests: 26.121 seconds
- //完成的请求数量
- Complete requests: 1000
- //失败的请求数量
- Failed requests: 0
- Write errors: 0
- Non-2xx responses: 1001
- //整个场景中的网络传输量,即所有请求的响应数据的总和,包含头信息和正文长度
- Total transferred: 299299 bytes
- //整个场景中的HTML内容传输量,即所有请求中响应数据的正文长度,不包含头信息的长度
- HTML transferred: 0 bytes
- //吞吐率:即每秒处理的请求数,相当于LR中的每秒事务数,括号中的mean表示这是一个平均值,其值为Complete requests/Time taken for tests
- Requests per second: 38.28 [#/sec] (mean)
- //平均请求等待的时间:相当于LR中的平均事务响应时间,其值为Time taken for tests/(Complete requests/Concurrency Level)
- Time per request: 261.206 [ms] (mean)
- //服务器平均请求处理的时间,即每个请求实际运行时间的平均值,其值为Time per request/Concurrency Level
- Time per request: 26.121 [ms] (mean, across all concurrent requests)
- //平均每秒网络上的流量,即这些请求在单位内从服务器获取的数据长度,其值为(Total transferred/Time taken for tests/)1024
- //这个统计选项可以很好的说明服务器在处理能力达到极限时其出口带宽的需求量
- //可以帮助排除是否存在网络流量过大导致响应时间延长的问题
- Transfer rate: 11.19 [Kbytes/sec] received
- //网络上消耗的时间的分解,各项数据的具体算法还不是很清楚
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 85 222 101.0 205 1224
- Processing: 12 38 23.4 34 151
- Waiting: 12 37 23.5 33 151
- Total: 144 259 100.9 244 1268
- //整个场景中所有请求的响应情况,在场景中每个请求都有一个响应时间
- //下面结果表明,50%的用户响应时间(即请求处理时间,这里处理时间是指Time per request)小于244毫秒
- //66%的用户响应时间小于252毫秒,而最大的响应时间小于1268毫秒
- //对于并发请求,实际上CPU并不是同时处理的,而是按照每个请求获得的时间片而逐个轮转处理的
- //所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数
- Percentage of the requests served within a certain time (ms)
- 50% 244
- 66% 252
- 75% 254
- 80% 255
- 90% 260
- 95% 481
- 98% 665
- 99% 686
- 100% 1268 (longest request)
获取网站信息
- [Jadyer@Jadyer-RHEL63 ~]$ curl -Is https://epay.10010.com/
- HTTP/1.1 302 Moved Temporarily
- Date: Tue, 06 Nov 2012 17:52:13 GMT
- Server: Apache-Coyote/1.1
- Location: http://epay.10010.com/404.jsp
- Content-Type: text/vnd.wap.wml;chartset=gbk;charset=GBK
- Set-Cookie: JSESSIONID=9DDBCA78C7FEF4ABECD070E744CE926C; Path=/