Apache (HTTPD) has 3 core MPM (multi-processing module, multi-process processing modules) working mode, respectively Prefork,worker and event, The httpd-2.2 event mode is still the model used for testing, while the httpd-2.4 event mode can be used in a production environment. If the HTTPD service is installed through Yum, the configuration files for 3 operating modes are default in /etc/httpd/conf/httpd.conf .
Prefork MPM, multi-process model, each process responds to a request
A Master process: responsible for generating sub-processes and recycling child processes, responsible for creating sockets, responsible for receiving requests and distributing them to a sub-process for processing;
N Child processes: Each child process processes a request;
Work model: Several idle processes are pre-generated, waiting to be used in response to user requests.
Default configuration for Prefork (httpd2.2) <ifmodule prefork.c> startservers 8 #进程启动后立即启动的空闲进程数量 Minspareservers 5 #最小空闲进程数量 maxspareservers #最大空闲进程数量 serverlimit Maximum number of processes allowed in a cycle maxclients #最大允许启动的服务器子进程数量 maxrequestsperchild 4000 # The maximum number of requests allowed (the process will be closed if the quantity is exceeded, set to 0 will never expire)</IfModule>
Worker MPM, multi-process multithreaded model, each thread processes a user request
A Master process: responsible for generating child processes, creating sockets, receiving requests, and distributing them to a sub-process for processing;
N Child processes: Each child process is responsible for generating multiple threads;
Per thread: Responsible for responding to user requests, the number of concurrent responses is: M*n (m: Number of child processes; N: The maximum number of threads each child process can create).
Default configuration for Worker (httpd2.2) <ifmodule worker.c> startservers 3 maxclients Minsparethreads maxsparethreads threadsperchild #每个子进程所能创建的最大线程数量 Maxrequestsperchild 0 #0表示不限制</IfModule>
Event MPM, incident-driven model (multi-process mode), each process responding to multiple requests
A Master process: responsible for generating child processes, responsible for creating sockets, receiving requests and distributing them to a child process for processing
N subprocess: Responds directly to multiple requests based on the event-driven mechanism, with the number of concurrent responses: M*n (m: Number of child processes; N: Number of requests per child process response).
<ifmodule mpm_event_module> (httpd2.4) startservers 3 minsparethreads Maxsparethreads threadsperchild maxrequestworkers maxconnectionsperchild 0</ifmodule> attached: httpd2.2 The configuration content of the event model is not given by default, but from the results of the test run, the configuration should be close to the worker model.
Compare httpd2.2 and httpd2.4
①httpd2.2 does not support compiling multiple MPM modules at the same time, only at compile time to select which one to use, this RPM package provides three application files: httpd (prefork), Httpd.worker, Httpd.event, respectively, is used to support different MPM mechanisms, and the default module is/USR/SBIN/HTTPD, which is the Prefork MPM module.
If you want to change the MPM, directly modify the configuration file /etc/sysconfig/httpd:
Httpd=/usr/sbin/httpd. {Worker,event}
Restart service httpd Restart after modification, now available via PS aux | grep httpd or Htttpd-m | grep MPM to see if the replacement was successful.
②HTTPD2.4 supports the dynamic compilation of multiple MPM modules, if you want to replace MPM, modify the configuration file /etc/httpd/conf.modules.d/00-pmp.conf:
LoadModule Mpm_{worker,event}_module modules/mod_mpm_{worker,event}.so
Restart Service Systemctl Restart Httpd.service when modified, now available via PS aux | grep httpd or Htttpd-m | grep MPM to see if the replacement was successful.
attached: httpd2.4.6 does not give the default configuration of 3 MPM directly, but the /usr/share/doc/httpd-2.4.6/httpd-mpm.conf file can be used to view the relevant configuration If we want to modify the configuration, refer to the documentation to modify the /etc/httpd/conf/httpd.conf file. Here I have modified the worker MPM, which reads as follows:
httpd2.4 switch to the worker model, you need to modify the configuration file /etc/httpd/conf.modules.d/00-mpm.confas follows:
Restart the httpd service and discover that there are 7 threads, even if the default configuration is 1 more threads, no reason is found:
HTTPD's prefork, worker, event