利用ab压力工具对服务器进行压力测试

 

假如我们需要对http://letv.com进行压力测试,指定请求总数为100,并发用户数为10,我们可以以下面的方式进行测试

$ ab -n 100 -c 10 http://letv.com/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking letv.com (be patient).....done


Server Software:        nginx/1.2.1
Server Hostname:        letv.com
Server Port:            80

Document Path:          /
Document Length:        184 bytes

Concurrency Level:      10
Time taken for tests:   0.396 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      37300 bytes
HTML transferred:       18400 bytes
Requests per second:    252.29 [#/sec] (mean)
Time per request:       39.637 [ms] (mean)
Time per request:       3.964 [ms] (mean, across all concurrent requests)
Transfer rate:          91.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    5   0.9      5       8
Processing:     4   33  87.4      6     312
Waiting:        4   33  87.3      5     311
Total:          9   39  87.6     12     317

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     12
  75%     13
  80%     14
  90%     15
  95%    316
  98%    317
  99%    317
 100%    317 (longest request)

需要注意的几个字段是

Requests per second 吞吐率(reqs/s),该字段值为252.29,该值表明了服务器每秒能够处理的请求数量。
Time per request 平均请求处理时间,可以看到,该字段分为两行,有两个不同的值,代表了处理每隔请求所需要的时间,但是第一行的值是第二行的10倍。这是因为我们指定的并发数量为10,第一行为每次并发请求的平均耗时,第二行为每隔请求的耗时,因此,第一行值为第二行的值乘上并发请求数量。可以尝试将并发数改为20,这样就会看到第一行是第二行的20倍。
Transfer rate 每秒从服务器获取的数据的长度。

上面的介绍的是linux中,下面来看看Windows环境下Apache服务器压力测试工具ab使用说明

在Apache服务器自带了一个测试程序Ab.exe可以很方便的使用 。。

进入cmd,之后进入ab.exe的目录

命令是 ab -c 请求数 -n 线程数 网址(建议输入目标网页)。。

线程数不宜过大 按照你电脑的承受能力 。。。

例:ab -n 10 -c 10 http://192.168.1.3/index.html

结果如下 。。


D:Apachebin>ab -n 10 -c 10 http://192.168.1.3/index.html 
(以上是输入的命令)

Benchmarking 192.168.1.3 (be patient).....done 
Server Software:        Apache/2.0.63 
(目标服务器Apache版本号)

Server Hostname:        192.168.1.3 
(目标服务器主机头名称)

Server Port:            80 
(目标服务器Apache端口)

Document Path:          /index.html 
(目标网页相对地址)

Document Length:        292 bytes 
(目标网页大小)

Concurrency Level:      10 
(并发线程数)

Time taken for tests:   0.140625 seconds 
(使用时间)

Complete requests:      10 
(成功的请求数量)

Failed requests:        0 
(失败的请求数量)

Write errors:           0 
(发生错误数量)

Total transferred:      5750 bytes 
(全部使用的流量)

HTML transferred:       2920 bytes 
(Html文件使用的流量)

Requests per second:    71.11 [#/sec] (mean) 
(指标一 平均每秒请求数)

Time per request:       140.625 [ms] (mean) 
(指标二 平均事务响应时间)

Time per request:       14.063 [ms] (mean, across all concurrent requests) 
(每秒请求时间)

Transfer rate:          35.56 [Kbytes/sec] received 
(传输速率)

Connection Times (ms) 
             min  mean[+/-sd] median   max 
Connect:        0    0   0.0      0       0 
Processing:   109  124  16.3    140     140 
Waiting:      109  124  16.3    140     140 
Total:        109  124  16.3    140     140 
(所有请求的响应情况)

Percentage of the requests served within a certain time (ms) 
50%    140 
66%    140 
75%    140 
80%    140 
90%    140 
95%    140 
98%    140 
99%    140 
100%    140 (longest request)

每个请求都有一个响应时间 。。

比如 其中 50% 的用户响应时间小于 140 毫秒 。。 
最大的响应时间小于 140 毫秒 (100% 处) 。。

posted @ 2018-02-23 18:51  DrKang  阅读(195)  评论(0编辑  收藏  举报