一:ab.exe的使用
ab.exe是Apache附带的压力测试工具,可以在web服务器本地模拟发起测试请求
1:进入Apache的bin目录
#输入命令
ab.exe -n 1000 -c 100 http://localhost/test/index.php;
index.php
<?php
#用循环来模拟处理业务逻辑
for($i = 0; $i <= 100; $i++) {
echo $i . '|';
}
CMD测试数据
Server Software: Apache/2.4.23
Server Hostname: localhost
Server Port: 80
Document Path: /index.php;
Document Length: 208 bytes
Concurrency Level: 100
Time taken for tests: 0.314 seconds #访问的总时间
Complete requests: 1000 #访问的总次数
Failed requests: 0 #失败的访问次数
Non-2xx responses: 1000
Total transferred: 418000 bytes
HTML transferred: 208000 bytes
Requests per second: 3182.42 [#/sec] (mean) #每秒访问多少次
Time per request: 31.423 [ms] (mean) #这么多人(100人)访问一次的时间
Time per request: 0.314 [ms] (mean, across all concurrent requests)
Transfer rate: 1299.07 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 1
Processing: 6 30 4.5 31 46
Waiting: 3 22 6.2 23 39
Total: 6 30 4.5 31 46
Percentage of the requests served within a certain time (ms)
50% 31
66% 32
75% 32
80% 32
90% 33
95% 34
98% 37
99% 37
100% 46 (longest request)
2、增大并发数到500
ab.exe -n 10000 -c 500 http://localhost/test/index.php;
会出现下面的情况
Benchmarking localhost (be patient)
Completed 1000 requests
Test aborted after 10 failures
apr_socket_connect(): 由于目标计算机积极拒绝,无法连接。 (730061)
Total of 1299 requests completed
是因为Apache默认的最大并发数是150
可以更改conf/extra/httpd-mpm.conf来更改最大并发数
二:
打开httpd.conf配置文件,打开下面的配置
# Server-poolmanagement (MPM specific)
Include conf/extra/httpd-mpm.conf
在apache/bin 目录下 输入
httpd.exe -l;
显示
Compiled in modules:
core.c
mod_win32.c
mpm_winnt.c #说明是winnt模式
http_core.c
mod_so.c
打开conf/extra/httpd-mpm.conf文件
找到
<IfModule mpm_winnt_module>
ThreadsPerChild 150 #改成1000即可
MaxRequestsPerChild 3000
</IfModule>
重启服务器,重新运行
ab.exe -n 10000 -c 500 http://localhost/test/index.php;
会出现相似的结果
如果是其它模式,更改httpd-mpm.conf对应的位置即可
<IfModule mpm_prefork_module>
StartServers 5 #开始启动的进程
MinSpareServers 5 #最小准备进程
MaxSpareServers 10 #最大空闲进程
MaxRequestWorkers 1000 #最大并发数
MaxConnectionsPerChild 0
</IfModule>