Introduction to apache2.4.x mpm

Source: Internet
Author: User

Introduction to three MPM types

 

 

Apache 2.x supports plug-in parallel processing modules, called multipleRoad Processing Module(MPM ). When compiling Apache, You must select or select only one MPM. For Unix-like systems, there are several different MPM options that affect Apache's speed and scalability.

  Prefork mpm: This multi-path processing module (MPM) implements a non-thread-type, pre-derived Web server, which works in a way similar to Apache 1.3. It is suitable for systems that do not have a thread security library and need to avoid thread compatibility issues. It is the best MPM for each request to be independent from each other, so that if a request fails, it will not affect other requests.

This MPM has a strong self-regulation capability and requires only a small amount of configuration instructions. The most important thing is to set maxclients to a value that is large enough to handle potential request peaks. At the same time, it cannot be too large, so that the memory used exceeds the physical memory size.

 

  Worker mpm: This multi-path processing module (MPM) enables network servers to support mixed multi-threaded Multi-process. Because a thread is used to process requests, a large number of requests can be processed, and the overhead of system resources is less than the process-based MPM. However, it also uses multiple processes, and each process has 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 reduces the number of processes based on the load. A separate control process (parent process) is responsible for the establishment of Child processes. Each sub-process can establish a threadsperchild number of service threads and a listening thread. The listening thread monitors access requests and passes them to the service thread for processing and response.

 

In either the worker mode or the prefork mode, Apache always tries to keep some spare (spare) or idle sub-processes (idle service thread pool) to meet the upcoming requests. In this way, the client does not need to wait for the sub-process to generate before obtaining the service.

 

  Event mpm: The above two stable MPM methods are insufficient for extremely busy server applications. Although the HTTP keepalive method can reduce the number of TCP connections and network load, but keepalive needs to be bound to the service process or thread, which causes a busy server to consume all the threads. Event MPM is a new model to solve this problem. It separates service processes from connections. When the server processes fast and has a very high click rate, the number of available threads is the key resource limit system. In this case, the event MPM method is the most effective. A busy server working in the worker MPM mode can withstand tens of thousands of visits per second (for example, during peak hours of large news service sites), and event MPM can be used to handle higher loads. It is worth noting that event MPM cannot work with secure HTTP (https) access.

Apache provides the following warning for Event Mode:

This MPM is experimental, so it may or may not work as expected.

This MPM is currently being tested and may not work as expected.

 

 

How to configure three MPM types

 

Prefork is the default MPM on the UNIX platform. It adopts the pre-Dispatch mode and the mode used in Apache 1.3. The prefork itself does not use threads, and Version 2.0 uses it to maintain compatibility with version 1.3. On the other hand, mongok uses a separate sub-process to handle different requests, the process is independent from each other, which makes it one of the most stable MPM.

How to view the three MPM of the currently installed Apache.

[root@localhost apache]# httpd -lCompiled in modules:  core.c  prefork.c  http_core.c  mod_so.c

If you see ipvk. C, it indicates that the current MPM mode is running K. Worker. C indicates the worker MPM mode.

 

So how to set the Apache MPM?

You must specify the mode when installing the required Apache configuration:

  [root@localhost httpd-2.4.1]# ./configure --prefix=/usr/local/apache2worker --enable-so --with-mpm=worker   [root@localhost httpd-2.4.1]# make  [root@localhost httpd-2.4.1]# make install

Specify the -- with-MPM = Name option to specify MPM. Name is the name of the MPM you want to use. If the mode is not specified, the default value is prefork MPM.

 

How to configure it to event mpm?

Like the above method, you only need to add the following parameters during installation: -- enable-nonportable-atomics = Yes

Note that the event MPM may not support the old CPU.

 

 

Analysis of Three MPM Parameters

 

No matter which MPM you install Apache

Open the ../Apache/CONF/extra/httpd-mpm.conf file after installation, and find the following Configuration:

 

# Perfork mpm

<IfModule mpm_prefork_module>StartServers 5MinSpareServers 5MaxSpareServers 10MaxRequestWorkers 250MaxConnectionsPerChild 0</IfModule> 

# Startservers: Number of server processes started

# Minspareservers: the minimum number of server processes to save for backup

# Maxspareservers: the maximum number of server processes. Save the backup.

# Maxrequestworkers: the maximum number of server processes allowed to start

# Maxconnectionsperchild: A server process service with the maximum number of connections

After the "startservers" sub-process is initially created, the prefork control process creates a process to meet the needs of the minspareservers settings. Wait for one second to create two more processes. Wait for another second to create four more processes ...... In this way, the number of Created processes is increased exponentially, up to 32 processes per second until the value set by minspareservers is met. This mode eliminates the need to generate new processes when requests arrive, thus reducing system overhead and increasing performance. Maxspareservers sets the maximum number of idle processes. If the number of idle processes is greater than this value, Apache automatically kill unnecessary processes. This value should not be too large, but if it is 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 each sub-process can process. Each sub-process will automatically destroy it after processing "maxrequestsperchild" requests. 0 means that the sub-process will never be destroyed. Although the default value is 0, each sub-process can process more requests, setting it to a non-zero value also has two important advantages:

1. prevent accidental Memory leakage. 2. When the server load drops, the number of sub-processes is automatically reduced.

Therefore, you can adjust this value based on the server load.

The maxrequestworkers Instruction Set also limits the number of service requests. Any connection attempt on maxrequestworkerslimit will usually be queued, up to several Based on the listenbacklog command.

Maxrequestworkers earlier than apache2.3.13 is called maxclients.

(Maxclients is the most important of these commands. It sets the request that Apache can process at the same time and is the parameter that has the greatest impact on Apache performance. The default value of 150 is far from enough. If the total number of requests has reached this value (you can confirm it through PS-Ef | grep HTTP | WC-l), the subsequent requests will be queued, until a processed request is completed. This is the main reason why there are still a lot of system resources and HTTP access is slow. In theory, the larger the value, the more requests can be processed, but the default limit of Apache cannot be greater than 256 .)

 

# Worker mpm

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

# Startservers: the initial number of server processes started

# Minsparethreads: the minimum number of worker threads to save for backup.

# Maxsparethreads: the maximum number of worker threads to save for backup

# Threadsperchild: a fixed number of worker threads on each server

# Maxrequestworkers: Maximum number of worker threads

# Maxconnectionsperchild: A server process service with the maximum number of connections

A worker generates a "startservers" sub-process by the main control process. Each sub-process contains a fixed number of threadsperchild threads, and each thread processes Requests independently. Similarly, minsparethreads and maxsparethreads set the minimum and maximum number of Idle threads in order not to generate a thread when the request arrives;

Maxrequestworkers sets the maximum number of clients simultaneously connected. If the total number of threads in the existing sub-process cannot meet the load, the control process will derive a new sub-process

The maximum default values of minsparethreads and maxsparethreads are 75 and 250, respectively. These two parameters have little impact on Apache performance and can be adjusted as needed.

Threadsperchild is the most performance-related command in worker MPM. The maximum default value of threadsperchild is 64. If the load is large, 64 is not enough. The threadlimit command must be explicitly used. The maximum default value is 20000.

In worker mode, the total number of requests that can be processed simultaneously is determined by the total number of sub-processes multiplied by the value of threadsperchild. The value must be greater than or equal to maxrequestworkers. If the load is large and the number of existing sub-processes cannot meet the requirements, the control process will derive a new sub-process. By default, the maximum number of sub-processes is 16. When you increase the number, you must explicitly declare serverlimit (the maximum value is 20000 ). Note that if serverlimit is explicitly declared, the value multiplied by threadsperchild must be greater than or equal to maxrequestworkers, and maxrequestworkers must be an integer multiple of threadsperchild, otherwise, Apache automatically adjusts to a corresponding value.

 

# Event mpm

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

# Startservers: the initial number of server processes started

# Minsparethreads: the minimum number of worker threads to save for backup.

# Maxsparethreads: the maximum number of worker threads to save for backup

# Threadsperchild: a fixed number of worker threads on each server

# Maxrequestworkers: Maximum number of worker threads

# Maxconnectionsperchild: A server process service with the maximum number of connections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.