Three MPM analysis of Apache prefork, worker and event

Source: Internet
Author: User

Three MPM Introductions

The Apache 2.X supports plug-in and walk-through modules, called multi-mode modules (MPM). When you are editing Apache, you have to select only one mpm, and for Unix systems, there are a few different mpm to choose from, which will affect the speed and extensibility of Apache.

Prefork MPM: This multi-process module (MPM) is a non-thread-type, predictable, Web server that works like Apache 1.3. It is suitable for a system that does not have a security library and needs to avoid the problem of the thread compatibility. It is the best mpm that asks each of you to be independent of each other, so that if one asks for a question, it will not affect the other request.

This MPM has a strong self-tuning capability and requires very little configuration instructions. The most important thing is to set the maxclients to a large enough number to handle the potential rush, not too big, so that the amount of memory that needs to be used is beyond the physical memory.

Worker MPM: This multi-process module (MPM) enables the network server to support mixed multi-thread multiple processes. Because of the use of the line to request, so can be handled a large amount of requests, and the system resources are less than the base of the process of MPM. However, it also uses multiple processes, each with multiple threads, to obtain the stability of the MPM based on the process.

Each process can have a fixed number of threads. The server will increase or decrease the number of processes depending on the download situation. The establishment of a single control process (the parent process) of the responsibility of the process. Each sub-process can establish a threadsperchild number of service and a monitoring process, the supervisor listens to the access request and will be transferred to the service process and answer it.

Whether it's worker mode or Prefork mode, Apache is always trying to keep some of the ready (spare) or idle sub-processes (The idle service pool) to greet the coming request. This way, the client does not need to wait for the child to be in the process before being serviced.

Event MPM: These two stable MPM methods are somewhat inadequate in the case of very busy service. Although the KeepAlive method of HTTP can reduce the number of TCP connections and network load, but keepalive need to process the kimono or the kidnapped, which leads to a busy service will consume all the distance. The Event MPM is a new model that solves this problem by separating the service from the connection. The event MPM method is most effective when the server is working at a very fast speed and has a very high bit rate at the same time, the available number of threads is the key resource limit. A busy service that works as a worker mpm can withstand a number of visits per second (such as at the peak of a large new news service station), and event MPM can be used to handle higher loads. It is important to note that theEvent MPM does not work on secure HTTP (HTTPS) visits .

For the event mode, Apache gave the following warning:

This MPM was experimental, so it could or may not be work as expected.

This MPM is currently under test, and he may not be able to work as expected.

How to configure three MPM

Prefork is the default MPM on the UNIX platform, and its expected derivation is also the model used in Apache 1.3. The prefork itself is not using a thread, and version 2.0 uses it to maintain compatibility with version 1.3, and on the other hand, the Perfork uses separate sub-processes to process different requests, which are independent of each other, making it one of the most stable mpm.

How to view the three mpm of the pre-installed Apache.

[Email protected] apache]# httpd-l

Compiled in Modules:

Core.c

Prefork.c

Http_core.c

Mod_so.c

If you see PERFORK.C, it means perfork mpm mode. WORKER.C is represented as the worker MPM mode.

So how do you set up Apache's MPM?

You need to specify the mode for the Apache configuration installation:

[Email protected] httpd-2.4.1]#/configure--prefix=/usr/local/apache2worker--enable-so--with-mpm=worker

[[email protected] httpd-2.4.1]# make

[[email 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, it 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.

Three kinds of MPM parameters analysis

No matter what kind of mpm you're installing Apache

After the installation is complete, open the./apache/conf/extra/httpd-mpm.conf file and locate the following configuration:

# perfork MPM

<ifmodule mpm_prefork_module>

Startservers 5

Minspareservers 5

Maxspareservers 10

Maxrequestworkers 250

Maxconnectionsperchild 0

</IfModule>

# Startservers: The number of service starts

# Minspareservers: Minimum number of service for the process, storage

# Maxspareservers: Maximum number of service, storage

# Maxrequestworkers: The maximum number of services Cheng start

# Maxconnectionsperchild: One server for maximum connectivity service

Prefork control process after the initial establishment of the "Startservers" sub-process, to meet the needs of Minspareservers Setup to create a process, waiting for a second clock, continue to create two, and then wait a second clock, continue to create four ... Increase the number of created processes so that they are up to 32 per second, up to the value of minspareservers settings. This mode eliminates the need to produce new processes when asked for, and reduces the system's ability to increase performance. Maxspareservers set the maximum number of idle processes, and if the idle progression is greater than this value, Apache will kill some of the remainder of the process automatically. This value is not too large, but if the value is smaller than Minspareservers, Apache will automatically adjust it to minspareservers+1. If the station is larger, consider increasing minspareservers and maxspareservers at the same time.

Maxrequestsperchild is the number of requests that each sub-process can handle. Each child processes the "Maxrequestsperchild" request to destroy the self. 0 means infinite, that is, the sub-process is never destroyed. Although the default setting of 0 allows each child to process more requests, there are two important benefits if you set a non-0 value:

1, to prevent accidental leakage of internal storage. 2. When the service load drops, it will automatically reduce the number of the child.

Therefore, this value can be adjusted according to the load of the service.

Maxrequestworkers instruction set the number of times the request is limited. Any connection attempts at the Maxrequestworkerslimit will normally be queued, up to a number based on the listenbacklog instruction.

The previous version of Apache2.3.13 Maxrequestworkers was called maxclients.

(MaxClients is one of the most important of these directives, which is that Apache can be used at the same time to request that it is the most influential part of Apache performance.) Its default value of 150 is far from enough, if the sum has reached this value (can be confirmed by Ps-ef|grep Http|wc-l), then the request will be queued, until one has been processed to find out. This is the main reason why the system resources are left behind and HTTP interviews are slow. The bigger the value, the more you can handle, but the Apache limit is no greater than 256. )

# worker MPM

<ifmodule mpm_worker_module>

Startservers 3

Minsparethreads 75

Maxsparethreads 250

Threadsperchild 25

Maxrequestworkers 400

Maxconnectionsperchild 0

</IfModule>

# Startservers: Initial number of service start

# Minsparethreads: Minimum number of work threads, save for use

# Maxsparethreads: Maximum number of working threads, for storage

# Threadsperchild: Fixed number of work threads at each server

# Maxrequestworkers: Maximum number of work threads

# Maxconnectionsperchild: One server for maximum connectivity service

The Worker generates a "startservers" sub-process from the master control process, each of which contains a fixed number of threadsperchild, each with a single site request. In the same way, the Minsparethreads and maxsparethreads set the minimum and maximum number of idle-time parameters for the generation of a thread when not in the request.

The maxrequestworkers set the maximum number of clients to be connected at the same time. If the total number of threads in the process is not sufficient, the control process will derive new sub-processes

The maximum default values for Minsparethreads and Maxsparethreads are 75 and 250. These two parameters do not affect Apache's performance and can be adjusted in the actual situation.

Threadsperchild is the most closely related instruction to performance in the worker mpm. The maximum default value for Threadsperchild is 64, and if the load is larger, 64 is not enough. To use the THREADLIMIT directive at this time, its maximum default value is 20000.

The number of requests that can be handled at the same time in worker mode is determined by multiplying the total by the Threadsperchild value, which should be greater than the maxrequestworkers. If the load is large and now the number of sub-processes is not sufficient, the control process will derive new sub-processes. The maximum number of Serverlimit is 16, and it also needs to be shown at a maximum of 20000. It is important to note that if you explicitly understand serverlimit, then it is multiplied by the value of threadsperchild to be greater than maxrequestworkers, And maxrequestworkers must be the integer number of threadsperchild, or Apache will automatically adjust to a corresponding value.

# event MPM

<ifmodule mpm_event_module>

Startservers 3

Minsparethreads 75

Maxsparethreads 250

Threadsperchild 25

Maxrequestworkers 400

Maxconnectionsperchild 0

</IfModule>

# Startservers: Initial number of service start

# Minsparethreads: Minimum number of work threads, save for use

# Maxsparethreads: Maximum number of working threads, for storage

# Threadsperchild: Fixed number of work threads at each server

# Maxrequestworkers: Maximum number of work threads

# Maxconnectionsperchild: One server for maximum connectivity service

For example, to configure a configuration that supports up to 3000 concurrent requests, as follows:

<ifmodule mpm_event_module>
Startservers 3 #默认个子进程启动数 3
Serverlimit #这里指定 Maximum number of child threads is 32
Minsparethreads 300 # Idle minimum number of threads 300
Maxsparethreads #空闲最大线程数量 1000
Threadsperchild #每个子进程启动时固定的线程数为100
Threadlimit 300 # HERE Specifies the maximum number of threads is 300
Maxrequestworkers #服务器最大支持并发数 3000
Maxconnectionsperchild 0 #设置一个子进程数处理多少个请求后销毁此子进程. 0 is no limit.
</IfModule>

#需要注意的是 Serverlimit * Threadsperchild to be greater than maxrequestworkers

From http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html

Three MPM analysis of Apache prefork, worker and event

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.