標籤:apache worker mpm
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的預設情況
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
650) this.width=650;" src="http://redmine.intra.weibo.com/attachments/download/4956/%E6%97%A0%E6%A0%87%E9%A2%981.png" width="424" height="55" alt="%E6%97%A0%E6%A0%87%E9%A2%981.png" />
650) this.width=650;" src="http://redmine.intra.weibo.com/attachments/download/4955/%E6%97%A0%E6%A0%87%E9%A2%982.png" width="255" height="25" alt="%E6%97%A0%E6%A0%87%E9%A2%982.png" />
由此可見,Apache在啟動時,按照預設StartServers啟動3個子進程,並且由於已經符合最小空閑進程,故不再變化。
h2. 2、startServers*ThreadsPerChild < MinSpareThreads,MinSpareTreads為ThreadsPerChild的整數倍:
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 100
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
[[email protected] 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
!http://redmine.intra.weibo.com/attachments/download/4957/%E6%97%A0%E6%A0%87%E9%A2%983.png!
由於3個初始的子進程共提供75個線程,故不滿足100個最小空閑線程數的要求,所以apache新啟動一個子進程來提供額外的線程.
h2. 3、startServers*ThreadsPerChild < MinSpareThreads,MinSpareTreads為ThreadsPerChild的非整數倍:
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 90
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
[[email protected] 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
[[email protected] 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個。
h2. 4、startServers*ThreadsPerChild > MinSpareThreads
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 10
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
[[email protected] 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
[[email protected] 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
由此可見,當初始啟動的線程數已經滿足最小空閑線程,而沒有超過最大空閑線程,則不會再清除線程。
h2. 5、有請求時,已有線程數-請求數 < 最小空閑線程:
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
發送請求:
> 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個,則新啟動一個子進程。
本文出自 “Precious” 部落格,請務必保留此出處http://nikki.blog.51cto.com/8132348/1574148
【Web-Apache】Worker MPM探索