【Web-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>
由此可见,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>
[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
!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>
[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个。
h2. 4、startServers*ThreadsPerChild > MinSpareThreads
<pre>
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 10
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
</pre>
[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
由此可见,当初始启动的线程数已经满足最小空闲线程,而没有超过最大空闲线程,则不会再清除线程。
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。