【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的默认情况

<IfModule mpm_worker_module>
StartServers             3
 MinSpareThreads         75
MaxSpareThreads        250
ThreadsPerChild         25
MaxRequestWorkers      400
MaxConnectionsPerChild   0
</IfModule>

wKiom1SFRSfia09dAABx7Gb4DuI133.jpg

wKioL1SFReOz5i7IAAAeB2T453Q567.jpg

由此可见,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

wKiom1SFRXjyoeGaAAAhvJyscf4149.jpg
由于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个,则新启动一个子进程。

你可能感兴趣的:(apache,worker,mpm)