Apache Bench工具
可以在ApacheHTTP服务器的任何标准灌输的bin目录中找到ApacheBench工具。它可用于测试所需的任何Web服务器的响应时间,如果要在任务关键型服务器上线之前对其进行压力测试,则它很有用。
要使用该工具,请打开命令提示符(或终端),浏览Apachebin文件夹并找到程序ab,这是ApacheBench工具。运行该工具的最简单形式是使用单个URL。但是,您必须输入完整的文件名,否则该工具将为您提供无效的URL错误。
abhttp://www.google.com/index.html
这给出以下输出。
Benchmarking www.google.com (be patient).....done
Server Software: gws
Server Hostname: www.google.com
Server Port: 80
Document Path: /index.html
Document Length: 231 bytes
Concurrency Level: 1
Time taken for tests: 0.94090 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Non-2xx responses: 1
Total transferred: 590 bytes
HTML transferred: 231 bytes
Requests per second: 10.63 [#/sec] (mean)
Time per request: 94.090 [ms] (mean)
Time per request: 94.090 [ms] (mean, across all concurrent requests)
Transfer rate: 0.00 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 41 0.0 41 41
Processing: 52 52 0.0 52 52
Waiting: 51 51 0.0 51 51
Total: 93 93 0.0 93 93在此示例中,该工具向Google服务器发出了一个请求。通过添加两个标志,可以使ApacheBench完成对服务器的多个并发请求。第一个标志是-n,用于告诉ApacheBench应该运行多少测试,如果使用数字5,则该工具将自身重复5次。第二个标志是-c,用于告诉ApacheBench应该建立多少个并发连接。下面的示例重复原始测试,但是这次使用-n和-c标志运行测试10次,每次运行10个连接。
ab-n10-c10http://www.google.com/index.html
这产生了以下输出。
Benchmarking www.google.com (be patient).....done
Server Software: gws
Server Hostname: www.google.com
Server Port: 80
Document Path: /index.html
Document Length: 231 bytes
Concurrency Level: 10
Time taken for tests: 0.229686 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Non-2xx responses: 10
Total transferred: 5900 bytes
HTML transferred: 2310 bytes
Requests per second: 43.54 [#/sec] (mean)
Time per request: 229.686 [ms] (mean)
Time per request: 22.969 [ms] (mean, across all concurrent requests)
Transfer rate: 21.77 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 55 9.1 55 68
Processing: 54 100 37.9 87 164
Waiting: 51 97 37.8 83 159
Total: 95 155 43.9 149 229
Percentage of the requests served within a certain time (ms)
50% 149
66% 175
75% 189
80% 210
90% 229
95% 229
98% 229
99% 229
100% 229 (longest request)在自己的服务器上运行该工具时,您很少会看到这样的时间。例如,在使用标准Wordpress安装的本地服务器上以相同参数运行该工具时,最长请求时间为4227。
要查找可用选项的列表,只需键入以下内容。
ab-h