一: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.23Server Hostname: localhostServer Port: 80Document Path: /index.php;Document Length: 208 bytesConcurrency Level: 100Time taken for tests: 0.314 seconds #訪問的總時間Complete requests: 1000 #訪問的總次數Failed requests: 0 #失敗的訪問次數Non-2xx responses: 1000 Total transferred: 418000 bytesHTML transferred: 208000 bytesRequests 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] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.3 0 1Processing: 6 30 4.5 31 46Waiting: 3 22 6.2 23 39Total: 6 30 4.5 31 46Percentage 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 requestsTest aborted after 10 failuresapr_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>