apache2中的worker模式。
说明:
官方介绍:
This Multi-Processing Module (MPM) implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server. However, it retains much of the stability of a process-based server by keeping multiple processes available, each with many threads.
worker 模式的最大优点:高处理效率。
出于稳定和跨平台的考虑,apache2 默认编译 为 prefork模式(多进程模式)。 一,apache worker模式的编译和安装:
#有关参数的解释和更多参数,可使用 --help 参数 获得帮助
[root@itnetcn httpd-2.2.17]$ ./configure --prefix=/usr/local/apache2worker --enable-so --with-mpm=worker [root@itnetcn httpd-2.2.17]$ make clean [root@itnetcn httpd-2.2.17]$ make [root@itnetcn httpd-2.2.17]$ su [root@RedhatFancp httpd-2.2.17]$ mkdir /usr/local/apache2worker [root@RedhatFancp httpd-2.2.17]$ chown fancp /usr/local/apache2worker [root@RedhatFancp httpd-2.2.17]$ exit [root@itnetcn httpd-2.2.17]$ make install [root@jitnetcn httpd-2.2.17]$ /usr/local/apache2worker/bin/apachectl start
1,查看到五个进程:
[root@jbxue bin]$ ps -ef |grep httpd
fancp 15242 1 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 15243 15242 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 15244 15242 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 15246 15242 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 15248 15242 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 15329 4762 0 23:19 pts/1 00:00:00 grep httpd 从以上进程列表,发现进程 15242 的父进程 pid 是1,同时它也是 进程 15243,15244,15246, 15248 的父进程。 为什么是5个进程呢?5个进程之间有什么关系呢? mpm_default.h 中设置了默认进程数(DEFAULT_START_DAEMON),最大进程数(DEFAULT_MAX_FREE_DAEMON),最小进程数(DEFAULT_MIN_FREE_DAEMON)。 在没有参数配置的情况下,会应用这些值。在 2.2.17 的版本中, DEFAULT_START_DAEMON 的值是 3。 所以,上面的5个进程的组成是:一个listen 进程,3个 recv进程.还有一个进程,我就不知道啦。
2,修改配置文件 http.conf,加入以下内容,设置主线程为1:
# worker MPM
# StartServers: initial number of server processes to start # MaxClients: maximum number of simultaneous client connections # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_worker_module> StartServers 1 MaxClients 15 MinSpareThreads 1 MaxSpareThreads 1 ThreadsPerChild 1 MaxRequestsPerChild 0 </IfModule>
3,查看进程:
[root@itnetcn httpd-2.2.17]$ /usr/local/apache2worker/bin/apachectl restart
[root@itnetcn httpd-2.2.17]$ ps -ef |grep httpd fancp 15242 1 0 23:19 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 16035 15242 0 23:45 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 16036 15242 0 23:45 ? 00:00:00 /usr/local/apache2worker/bin/httpd -k start fancp 16041 4762 0 23:45 pts/1 00:00:00 grep httpd (责任编辑:IT) |