刚开始的时候,对于压力测试感觉就是空白一片,后来查了查资料感觉其实一旦入门,一切不会是想象中那么难。
进入cmd命令行模式,把目录切换到apache下的ab.exe所在的路径,我装的是集成的appserv,所以路径是:D:\AppServ\Apache2.2\bin,这个都是次要的,只要有Apache的ab.exe就能够进行压力测试。
然后在这个下面键入:ab -n 1000 -c 50 http://localhost/site/index.php
然后就会返回结果了:
D:\AppServ\Apache2.2\bin>ab -n 1000 -c 50 http://localhost/site/test.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (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
Finished 1000 requests
Server Software: Apache/2.2.8
Server Hostname: localhost
Server Port: 80
Document Path: /site/test.php //请求的资源
Document Length: 26 bytes // 文档返回的长度,不包括相应头
Concurrency Level: 50 // 并发个数
Time taken for tests: 12.485334 seconds //请求消耗的总时间
Complete requests: 1000 //总请求数
Failed requests: 0
Write errors: 0
Total transferred: 219000 bytes
HTML transferred: 26000 bytes
Requests per second: 80.09 [#/sec] (mean) // 平均每秒的请求数
Time per request: 624.267 [ms] (mean) // 平均每个请求消耗的时间
Time per request: 12.485 [ms] (mean, across all concurrent requests)// 就是上面的时间除以并数
Transfer rate: 17.06 [Kbytes/sec] received // 时间传输速率
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 6.8 0 31
Processing: 219 604 66.2 593 906
Waiting: 218 603 66.3 593 906
Total: 234 608 66.0 593 921
Percentage of the requests served within a certain time (ms)
50% 593 // 就是有50%的请求都是在85ms内完成的
66% 609
75% 625
80% 625
90% 687
95% 734
98% 750
99% 859
100% 921 (longest request)
含义: 同时处理50个并发请求并运行 1000 次index.php
结果: 在并发50个请求的情况下,完成1000次的访问请求,共花了12.485秒,这个程序每秒可处理80.09个请求。
当然这是本地环境,所以测试的结果相对来说是好一些,如果涉及到web的站点,考虑的因素就不止这些了。