Author:小怪獸Nikki 微博:@再見了小怪獸
去除http.conf中Include conf/extra/httpd-mpm.conf前的#,以使httpd-mpm.conf中的配置生效。
#Server-pool management (MPM specific) Include conf/extra/httpd-mpm.conf
一、Apache的默認情況
<IfModule mpm_worker_module> StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 </IfModule>
由此可見,Apache在啓動時,按照默認StartServers啓動3個子進程,並且由於已經符合最小空閒進程,故不再變化。
二、startServers*ThreadsPerChild < MinSpareThreads,MinSpareTreads爲ThreadsPerChild的整數倍:
<IfModule mpm_worker_module> StartServers 3 MinSpareThreads 100 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 </IfModule>
[root@testhadoop-slave1 extra]# ps -ef|grep httpd root 43900 1 0 03:37 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 43903 43900 0 03:37 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 43904 43900 0 03:37 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 43911 43900 0 03:37 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 44087 43900 0 03:37 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start root 45907 20322 0 03:37 pts/0 00:00:00 grep httpd
由於3個初始的子進程共提供75個線程,故不滿足100個最小空閒線程數的要求,所以apache新啓動一個子進程來提供額外的線程.
三、startServers*ThreadsPerChild < MinSpareThreads,MinSpareTreads爲ThreadsPerChild的非整數倍:
<IfModule mpm_worker_module> StartServers 3 MinSpareThreads 90 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 </IfModule>
[root@testhadoop-slave1 extra]# ps -ef|grep httpd root 38933 1 0 03:46 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 38937 38933 0 03:46 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 38938 38933 0 03:46 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 38942 38933 0 03:46 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 39112 38933 0 03:46 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start
[root@testhadoop-slave1 bin]# sh jingjingtest/test.sh 38937:26 38938:26 38942:26 38937:26 38938:26 38942:26 39112:26
由此可見apache在啓動3個子進程後又啓動一個子進程,但是並沒有給新的子進程新建90-25*3=15個線程,而是也生成26個線程(其中一個爲監控線程),新子進程的線程數爲:ThreadsPerChild個。
四、startServers*ThreadsPerChild > MinSpareThreads
<IfModule mpm_worker_module> StartServers 3 MinSpareThreads 10 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 </IfModule>
[root@testhadoop-slave1 extra]# ps -ef|grep httpd root 21985 1 0 03:53 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 21987 21985 0 03:53 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 21988 21985 0 03:53 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start daemon 21992 21985 0 03:53 ? 00:00:00 /data2/irunner9001/lamp/apache//bin/httpd -k start root 23846 20322 0 03:53 pts/0 00:00:00 grep httpd [root@testhadoop-slave1 bin]# sh jingjingtest/test.sh 21987:26 21988:26 21992:26 21987:26 21988:26 21992:26 21987:26 21988:26 21992:26 21987:26 21988:26 21992:26
由此可見,當初始啓動的線程數已經滿足最小空閒線程,而沒有超過最大空閒線程,則不會再清除線程。
五、有請求時,已有線程數-請求數 < 最小空閒線程:
<IfModule mpm_worker_module> StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 </IfModule>
發送請求:
ab -n 10000 -c 10 http://10.210.228.50:9001/
各子進程線程情況:
---
19202:26
19203:26
19210:26
---
19202:26
19203:26
19210:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
---
19202:26
19203:26
19210:26
20082:26
由此可以看出,初始有3個子進程,共有3*25=75個線程,當有10個請求到來,存在空閒線程不足minSpareThread個,則新啓動一個子進程。