网站并发测试,网站服务使用的是apache2.4 因此使用ab来测试网站性能。
windows使用cms 打开apache/bin 运行ab.exe (......../apache/bin/ab),提示出很多参数,大家可以去查看,我就看了n和c其余没注意,
...... ab -n 200-c 100 http://localhost/test.php >>d:**** 测试结果会保持到****文件里。
第一次测试 200请求数 100并发 结果OK
第二次测试 500请求数 500并发 结果 近2000次fail
很是费解,查资料 需要配置apache的什么“多处理模块” 也就是conf目录下extra下的httpd-mpm.conf文件配置
默认:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>
修改后
<IfModule mpm_prefork_module>
ServerLimit 1000
StartServers 30
MinSpareServers 30
MaxSpareServers 40
MaxRequestWorkers 1000
MaxConnectionsPerChild 4000
</IfModule>
StartServers:当Apache被启动时,Apache会自动创建StartServers个进程,
MinSpareServers :将空闲进程数保持在MinSpareServers和MaxSpareServers之间。
MaxSpareServers :将空闲进程数保持在MinSpareServers和MaxSpareServers之间。
如果空闲进程小于MinSpareServers,Apache将会以大约每秒1个的速度新建进程。
如果空闲进程大于MaxSpareServers,Apache将会删除多余的空闲进程,释放服务器资源。
进程数的最大值由MaxRequestWorkers 控制,在Apache1.3中最大只能设置为256,但在Apache2.0中,可以通过在配置开头增加ServerLimit项目来突破256的限制,此时必须MaxClients ≤ ServerLimit ≤ 20000
MaxConnectionsPerChild 用来控制每个进程在处理了多少次请求之后自动销毁,这个参数可以设置为0表示无限(即不销毁进程)。
重启apache
继续测试
现在结果好多了
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 www.site1.com (be patient)
Server Software: Apache/2.4.4
Server Hostname: www.site1.com
Server Port: 80
Document Path: /search/pf/1.html
Document Length: 28355 bytes
Concurrency Level: 1000
Time taken for tests: 298.971 seconds
Complete requests: 5000
Failed requests: 10
(Connect: 3, Receive: 0, Length: 7, Exceptions: 0)
Write errors: 0
Total transferred: 143335307 bytes
HTML transferred: 141760307 bytes
Requests per second: 16.72 [#/sec] (mean)
Time per request: 59794.294 [ms] (mean)
Time per request: 59.794 [ms] (mean, across all concurrent requests)
Transfer rate: 468.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 55 165.9 0 1089
Processing: 13703 54289 13103.4 57385 70505
Waiting: 12896 36895 12487.2 37135 69721
Total: 13703 54344 13104.2 57412 70593
Percentage of the requests served within a certain time (ms)
50% 57412
66% 60102
75% 61825
80% 64498
90% 67807
95% 69000
98% 69520
99% 69998
100% 70593 (longest request)