Apache web server 簡易測試


測試環境:Ubuntu 20.04 LTS

Apache version:apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2021-10-14T16:24:43

default 配置下啟動apache server帶起兩個process以及(25+1) * 2個thread

ps aux | grep apache | grep www-data | wc -l
2
ps -efL | grep apache2 | grep www-data | wc -l
54

同時間點的request越高所需要的thread也就越多,但防禦上比來就是可以針對同一IP多去進行rate-limit

Apache配置

<IfModule mpm_event_module>
StartServers                     2
MinSpareThreads          25
MaxSpareThreads          75
# ServerLimit default 32 max 20000
ServerLimit             32
threadlimit             64
ThreadsPerChild          25
MaxRequestWorkers         1500
MaxConnectionsPerChild   0
</IfModule>

理論最高thread : 32 * (25+1) = 832 Max RequestWorkers是針對同一IP進行設定正常設定不應該超過最高thread數量這邊測試需求暫時不管

以下利用slowhttptest進行測試了解mpm_event底下的thread運作
case 1.

測試指令
slowhttptest -c 2000 -X -w 512 -y 1024 -n 5 -z 32 -k 3 -r 100 -u http://192.168.0.27 -p 3

root@test-Standard-PC:~# ps -aux | grep apache2 | grep www-data | wc -l
31
root@test-Standard-PC:~# ps -efL | grep apache2 | grep www-data | wc -l
837

該數字包含31個process,實際計算 31 * (25+1) + 31 = 837

case 2.

測試指令
slowhttptest -c 2000 -X -w 512 -y 1024 -n 5 -z 32 -k 3 -r 40 -u http://192.168.0.27 -p 3

ps -aux | grep apache2 | grep www-data | wc -l
27
root@test-Standard-PC:~# ps -efL | grep apache2 | grep www-data | wc -l
729

實際計算 27 * ( 25 +1) + 27 = 729

case 3.

測試指令
slowhttptest -c 2000 -X -w 512 -y 1024 -n 5 -z 32 -k 3 -r 200 -u http://192.168.0.27 -p 3

ps -aux | grep apache2 | grep www-data | wc -l
32
root@test-Standard-PC:~# ps -efL | grep apache2 | grep www-data | wc -l
864

此次測試直接把apache server打垮看到最高thread=864-32=832 = ServerLimit * (ThreadsPerChild+1)

Apache配置

<IfModule mpm_event_module>
StartServers                     2
MinSpareThreads          25
MaxSpareThreads          75
# ServerLimit default 32 max 20000
ServerLimit             32
threadlimit             64
ThreadsPerChild          25
MaxRequestWorkers         200
MaxConnectionsPerChild   0
</IfModule>

理論最高thread : 32 * (25+1) = 832
以下測試MaxRequestWorkers不同設定值時對應的thread數量

測試指令
slowhttptest -c 2000 -X -w 512 -y 1024 -n 5 -z 32 -k 3 -r 100 -u http://192.168.0.27 -p 3

Case 1.

MaxRequestWorkers 200

root@test-Standard-PC:~# ps -aux | grep apache2 | grep www-data | wc -l
9
root@test-Standard-PC:~# ps -efL | grep apache2 | grep www-data | wc -l
243 = (9 * (25+1)) + 9

Case 2.

MaxRequestWorkers 300

ps aux | grep apache2 | grep www-data | wc -l
12
root@test-Standard-PC:~# ps -efL | grep apache2 | grep www-data | wc -l
324 = (12 * (25+1)) + 12

可知 MaxRequestWorkers 由於啟動一個新process 會同時代起MinSpareThreads個數量之thread,因此實際看到thread會是 child process (ThreadsPerChild+1) > MaxRequestWorkers > (child process-1) (ThreadsPerChild+1)

#apache #slowhttptest






你可能感興趣的文章

Jest "Cannot find module from xxx" issue

Jest "Cannot find module from xxx" issue

[JS101] JavaScript - 常用的內建函式

[JS101] JavaScript - 常用的內建函式

瞭解function

瞭解function






留言討論