目的:在機(jī)器能夠承受情況下,達(dá)到最大請(qǐng)求連接數(shù)
概念:http的IO模式
prefork, worker, event,其中prefork為進(jìn)程模式,worker和event為線程的多路復(fù)用模式,本文以httpd傳統(tǒng)的prefork為例,也可以通過(guò)更改配置文件設(shè)置httpd的IO響應(yīng)模式
/etc/httpd/conf.modules.d/00-mpm.conf
準(zhǔn)備測(cè)試網(wǎng)頁(yè)
一般一個(gè)5Mb大小的文本文件test.txt,通常門口網(wǎng)站主頁(yè)大小,
- 調(diào)整prefork的配置,從2000個(gè)進(jìn)程開(kāi)始
StartServers 2000
MinSpareServers 5
MaxSpareServers 20
ServerLimit 2000 # 最多進(jìn)程數(shù),最大值 20000
MaxClients 2000 # 最大的并發(fā)連接數(shù)
MaxRequestsPerChild 4000 # 子進(jìn)程最多能處理的請(qǐng)求數(shù)量。
在服務(wù)端打開(kāi)vmstate
vmstat 1 #主要觀察內(nèi)存和swap情況
在client端測(cè)試httpd連接狀況,根據(jù)測(cè)試結(jié)果不斷調(diào)整profork進(jìn)程數(shù)大小
# ab命令為httpd-tools中的一個(gè)工具
# 輸出中主要的參數(shù)為Requests per second
ab -c1000 -n2000 http://ip/test.txt
Document Path: /
Document Length: 20 bytes
Concurrency Level: 10
Time taken for tests: 0.070 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 2650 bytes
HTML transferred: 200 bytes
Requests per second: 143.24 [#/sec] (mean)
Time per request: 69.813 [ms] (mean)
Time per request: 6.981 [ms] (mean, across all concurrent requests)
Transfer rate: 37.07 [Kbytes/sec] received