The Apache 2.X supports a plug-in parallel processing module called a multi- path processing module (MPM). When compiling Apache, you have to choose only one mpm, and there are several different MPM options for Unix-like systems that can affect the speed and scalability of Apache.
prefork MPM : This multi-path processing module (MPM) implements a non-threaded, pre-derived Web server that works like Apache 1.3. It is suitable for systems that do not have a thread-safe library and need to avoid threading compatibility issues. It is the best mpm to require each request to be independent of each other, so that if a request has a problem it will not affect the other request.
This MPM has a strong self-tuning capability and requires very little adjustment of the configuration instructions. The most important thing is to set the maxclients to a value that is large enough to handle the potential request spikes, and not too large to use more memory than the size of the physical memory.
Worker MPM : This multi-processing module (MPM) enables a network server to support mixed multithreaded multi-process. Because a thread is used to process requests, a large amount of requests can be processed, while the overhead of system resources is less than the process-based MPM. However, it also uses a multi-process, with each process having multiple threads to obtain the stability of the process-based MPM.
The number of threads that each process can have is fixed. The server increases or decreases the number of processes depending on the load. A separate control process (parent process) is responsible for the creation of child processes. Each child process can establish a threadsperchild number of service threads and a listener thread that listens to the access request and passes it to the service thread for processing and answering.
Whether it's worker mode or prefork mode, Apache always tries to keep some spare (spare) or idle child processes (the free service thread pool) to meet the incoming requests. This way, the client does not need to wait for the child process to be generated before the service is received.
Event MPM: Both of these stable MPM methods are somewhat inadequate under very busy server applications. Although the keepalive way of HTTP can reduce the number of TCP connections and network load, keepalive needs to be bound to the service process or thread, which causes a busy server to consume all the threads. The Event MPM is a new model for solving this problem, which separates the service process from the connection. The event MPM approach is most effective when the server is processing fast and has a very high click-through rate, the number of threads available is the critical resource limit. A busy server that works as a worker mpm can withstand a good tens of thousands of visits per second (for example, at the peak of a large news Service site), and event MPM is used to handle higher loads. It is important to note that the Event MPM does not work under secure HTTP (HTTPS) access.
For the event mode, Apache gives the following warning:
This MPM was experimental, so it could or may not be work as expected.
This MPM is currently under trial, and he may not be able to work as expected.
How to configure three types of MPM
The prefork is the default MPM on the UNIX platform, and the pre-derived subprocess method used in Apache 1.3 is also used in the pattern. Prefork itself is not using the thread, version 2.0 uses it to maintain compatibility with version 1.3, and on the other hand, the process of handling different instructions with separate sub-processes is independent of each other, which makes it one of the most stable mpm.
How to view the three types of MPM currently installed on Apache.
[Email protected] apache]# httpd-lcompiled in modules: core.c prefork.c http_core.c mod_so.c
If you see PERFORK.C, the current perfork MPM mode is indicated. The WORKER.C is represented as the worker MPM mode.
So how do you set up Apache's MPM?
You need to specify the mode when the Apache configuration is installed:
[Email protected] httpd-2.4.1]#/configure--prefix=/usr/local/apache2worker--enable-so--with-mpm=worker [email Protected] httpd-2.4.1]# make [[E-mail protected] httpd-2.4.1]# make install
Specifying the--WITH-MPM=NAME option specifies that Mpm,name is the name of the MPM you want to use. If you do not specify a pattern, the default is Prefork MPM.
So how do I configure it as an event MPM?
As with the method above, just add the following parameters to the installation:--enable-nonportable-atomics=yes
It is important to note that the event MPM may not be supported for older CPUs.
Analysis of three MPM parameters
No matter what kind of mpm you're installing in Apache,
After the installation is complete, open the./apache/conf/extra/httpd-mpm.conf file and locate the following configuration:
# perfork MPM
# startservers: Number of server processes started
# Minspareservers: Minimum number of server processes, saving alternate
# Maxspareservers: Maximum number of server processes, saving alternate
# Maxrequestworkers: Maximum number of server processes allowed to start
# Maxconnectionsperchild: One server process service with maximum number of connections
Prefork control process After initially establishing the "startservers" sub-process, in order to meet the needs of minspareservers settings to create a process, wait a second, continue to create two, wait a second, continue to create four ... This increases the number of processes created by the number of digits, up to 32 per second, until the value of the Minspareservers setting is met. This pattern eliminates the need to generate new processes when the request arrives, reducing overhead to increase performance. Maxspareservers sets the maximum number of idle processes, and if the number of idle processes is greater than this value, Apache will automatically kill some of the unwanted processes. This value should not be set too large, but if you set a value smaller than minspareservers, Apache will automatically adjust it to minspareservers+1. If the site load is large, consider increasing minspareservers and maxspareservers at the same time.
Maxrequestsperchild sets the number of requests that can be processed by each child process. Each child process is automatically destroyed after it has processed "maxrequestsperchild" requests. 0 means infinity, that is, the child process never destroys. Although the default setting of 0 enables each subprocess to process more requests, there are two important benefits if set to a value other than 0:
1. To prevent accidental memory leaks. 2. When the server load drops, the number of child processes will be automatically reduced.
Therefore, this value can be adjusted according to the load of the server.
The maxrequestworkers instruction set limits the number of service requests at the same time. Any connection attempts at Maxrequestworkerslimit will normally be queued, up to several based on the Listenbacklog directive.
Prior to apache2.3.13 version maxrequestworkers was called MaxClients.
(MaxClients is the most important of these directives, setting the request that Apache can process at the same time, which is the most influential parameter to Apache performance.) Its default value of 150 is far from enough, if the total number of requests has reached this value (can be confirmed by Ps-ef|grep Http|wc-l), then the subsequent request will be queued until a processed request is complete. This is the main reason why the system resources are still a lot left and HTTP access is slow. Although theoretically the larger the value, the more requests can be processed, but the Apache default limit cannot be greater than 256. )
# worker MPM
<ifmodule mpm_worker_module>startservers 3MinSpareThreads 75MaxSpareThreads threadsperchild 25MaxRequestWorkers 400MaxConnectionsPerChild 0</ifmodule>
# Startservers: Initial number of server processes started
# Minsparethreads: Minimum number of worker threads, saving alternate
# Maxsparethreads: Maximum number of worker threads, saving alternate
# Threadsperchild: Fixed number of worker threads in each server process
# Maxrequestworkers: Maximum number of worker threads
# Maxconnectionsperchild: One server process service with maximum number of connections
The Worker generates a "startservers" sub-process by the master control process, each of which contains a fixed number of threadsperchild threads, and each thread processes the request independently. Similarly, minsparethreads and maxsparethreads set the minimum and maximum number of idle threads in order not to generate threads when the request arrives;
The maxrequestworkers sets the maximum number of clients that are simultaneously connected. If the total number of threads in an existing child process does not meet the load, the control process will derive the new child process
The maximum default values for Minsparethreads and Maxsparethreads are 75 and 250, respectively. These two parameters have little effect on Apache performance, and can be adjusted according to the actual situation.
Threadsperchild is the most performance-related instruction in the worker mpm. The maximum default value for Threadsperchild is 64, and 64 is not enough if the load is large. At this point, to explicitly use the THREADLIMIT directive, its maximum default value is 20000.
The total number of requests that can be processed concurrently in worker mode is determined by multiplying the total number of child processes by the Threadsperchild value, which should be greater than or equal to maxrequestworkers. If the load is large and the number of existing child processes is not met, the control process derives the new child process. The default maximum number of child processes is 16, and you need to explicitly declare serverlimit (the maximum value is 20000) when you increase it. It is important to note that if Serverlimit is explicitly declared, then it must be multiplied by the value of threadsperchild to be greater than or equal to maxrequestworkers. And maxrequestworkers must be an integer multiple of threadsperchild, otherwise Apache will automatically adjust to a corresponding value.
# event MPM
# Startservers: Initial number of server processes started
# Minsparethreads: Minimum number of worker threads, saving alternate
# Maxsparethreads: Maximum number of worker threads, saving alternate
# Threadsperchild: Fixed number of worker threads in each server process
# Maxrequestworkers: Maximum number of worker threads
# Maxconnectionsperchild: One server process service with maximum number of connections
This article turns from http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html
Three ways to explain Apache's work model