Usage: ab[options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform //即requests,用于指定压力测试总共的执行次数。
-c concurrency Number of multiple requests to make at a time //即concurrency,用于指定压力测试的并发数。
-t timelimit Seconds to max. to spend on benchmarking //即timelimit,等待响应的最大时间(单位:秒)。
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes //即windowsize,TCP发送/接收的缓冲大小(单位:字节)。
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T //即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。
-u putfile File containing data to PUT. Remember also to set -T //即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。
-T content-type Content-type header to use for POST/PUT data, eg. //即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print //即verbosity,指定打印帮助信息的冗余级别。
-w Print out results in HTML tables //以HTML表格形式打印结果。
-i Use HEAD instead of GET //使用HEAD请求代替GET请求。
-x attributes String to insert as table attributes //插入字符串作为table标签的属性。
-y attributes String to insert as tr attributes //插入字符串作为tr标签的属性。
-z attributes String to insert as td or th attributes //插入字符串作为td标签的属性。
-C attribute Add cookie, eg. 'Apache=1234'. (repeatable) //添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip' //添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes //添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes //添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use ////指定使用的代理服务器和端口号,例如:"126.10.10.3:88"。
-V Print version number and exit //打印版本号并退出。
-k Use HTTP KeepAlive feature //使用HTTP的KeepAlive特性。
-d Do not show percentiles served table. //不显示百分比。
-S Do not show confidence estimators and warnings. //不显示预估和警告信息。
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-g filename Output collected data to gnuplot format file. //输出结果信息到gnuplot格式的文件中。
-e filename Output CSV file with percentages served //输出结果信息到CSV格式的文件中。
-r Don't exit on socket receive errors. //指定接收到错误信息时不退出程序。
-m method Method name
-h Display usage information (this message) //显示用法信息,其实就是ab -help。
-I Disable TLS Server Name Indication (SNI) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL2, TLS1, TLS1.1, TLS1.2 or ALL)
虽然ab可以配置的参数选项比较多,但是,一般情况下我们只需要使用形如ab -n数字 -c数字 url路径的命令即可。
譬如,我们对位于nginx服务器上、URL为
localhost/index.php的页面进行压力测试。测试总次数为1000,并发数为100(相当于100个用户同时访问,他们总共访问1000次)。
我们输入DOS命令ab -n 1000 -c 100 http://thinkphp5.com/admin/buyGood
打印结果如下:
root@homestead:/etc# ab -n 1000 -c 100 http://thinkphp5.com/admin/buyGood
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking thinkphp5.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
Server Software: nginx/1.15.8
Server Hostname: thinkphp5.com
Server Port: 80
Document Path: /admin/buyGood
Document Length: 44934 bytes
Concurrency Level: 100
Time taken for tests: 170.328 seconds
Complete requests: 1000
Failed requests: 120
(Connect: 0, Receive: 0, Length: 120, Exceptions: 0)
Non-2xx responses: 1000
Total transferred: 45089857 bytes
HTML transferred: 44933857 bytes
Requests per second: 5.87 [#/sec] (mean)
Time per request: 17032.818 [ms] (mean)
Time per request: 170.328 [ms] (mean, across all concurrent requests)
Transfer rate: 258.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.4 0 5
Processing: 873 16191 3288.7 16629 21512
Waiting: 872 16190 3288.6 16628 21510
Total: 878 16192 3287.5 16629 21512
Percentage of the requests served within a certain time (ms)
50% 16629
66% 17074
75% 17572
80% 18120
90% 19521
95% 20382
98% 20797
99% 20944
100% 21512 (longest request)
网友评论