压力测试工具ab.exe

该工具是apache自带的,可以用它来测试网站的并发量有多大和某个页面的访问时间。

基本用法:

1. 进入CMD,转到apache的bin目录下。

2.执行命令ab.exe  -n 访问的问次数–c 多少人访问(并发量) 访问的地址如:ab.exe –n 1000 –c 100 http://localhost/index.php;

如输入以下命令

ab.exe -n 10000 -c 100 http://127.0.0.1/test/index.php

index.php的内容为

<?php
for($i=0; $i<100; $i++){
    echo $i;
}

该命令的意思为100个人访问该地址1W次。会出现以下结果。

Server Software:        Apache/2.4.4                                      #apache版本号  
Server Hostname:        localhost  
Server Port:            80  
   
Document Path:          /test/index.php                       
Document Length:        5 bytes 
   
ConcurrencyLevel:      100  
Time taken fortests:   54.111 seconds                                     #访问的总时间(秒)  
Completerequests:      10000                                              #访问的总次数  
Failed requests:        0   
Write errors:           0  
Totaltransferred:      2060000 bytes  
HTMLtransferred:       50000 bytes  
Requests persecond:    184.80 [#/sec] (mean)                              #每秒访问多少次  
Time perrequest:       541.111 [ms] (mean)                                #这么多人(100)访问一次的时间  
Time perrequest:       5.411 [ms] (mean, acrossall concurrent requests)   #一个人访问一次花费的时间  
Transfer rate:         37.18 [Kbytes/sec] received

如果我们把并发数增加到500,即把命令调整成 ab.exe -n 10000 -c 500 http://localhost/test/index.php

它就会出现以下结果,原因是因为apache在windows下默认的最大并发访问量为150。

apr_socket_connect():由于目标计算机积极拒绝,无法连接。   (730061)  
Total of 902 requestscompleted

进行压力测试的适合需要注意点:

1.不要忘记修改服务器默认最大并发访问量为不限制。

2.测试机器与被测试机器分开。

3.不要对线上服务器做压力测试。

4.观察测试工具ab所在机器,以及被测试的前端机的CPU,内存,网络等都不要超过最高限度的75%。

为您推荐