Introduction to Apache MPM Module

Source: Internet
Author: User
Tags mixed require requires thread

Introduction of MPM Module

Multi-channel processing module, Multi-Processing modules,mpm. Responsible for binding the machine network port, accepting the request, and dispatching the subprocess to process the request.

Ii. Types of MPM modules

Prefork a non-threading, pre-derived MPM

The worker thread-type MPM implements a mixed multithreaded mpm that allows multiple threads to be included in a child process.

Event an experimental variant of a standard WORKERMPM

Mpm_winnt for MPM in the Windows Nt/windows 2000/windows xp/windows 2003 series

Mpm_netware, Novell NetWare optimized threading Multi-processor module (MPM)

MPMT_OS2 Hybrid multi-process multithreaded multi-channel module (MPM) specifically for OS/2 optimization

BeOS-Optimized multi-channel module (MPM) specifically for BeOS

One of our more commonly used in Linux is prefork and worker, Windows platform is more commonly used is mpm_winnt. BeOS is a multimedia operating system developed by be Company, NetWare is the UNIX product of Novell NetWare company, OS/2 is created by Microsoft and IBM, and a set of operating system developed by IBM, which is now dead, But it doesn't rule out the possibility of new-born open source. None of this is going to be a big use for us.

Third, preforking MPM

Overview

A MPM, pre-derived, or non-threaded. This multi-channel module (MPM) implements a non-threading, pre-built Web server that works like Apache 1.3. It is suitable for systems that do not have thread-safe libraries and need to avoid thread-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 does not affect other requests.

This mpm has a strong self-regulation capability and requires minimal configuration instruction tuning. The most important thing is to set the maxclients to a value that is large enough to handle the potential request spikes, but not too large to use more memory than the physical memory.

Working mode

A separate control process (the parent process) is responsible for generating the child processes that are used to listen for requests and respond. Apache always tries to keep some spare (spare) or idle subprocess to meet the incoming request. This allows the client to wait for the child process to occur before the service is received.

Startservers, Minspareservers, maxspareservers, maxclients directives are used to regulate how the parent process produces child processes. Typically, Apache has a strong self-regulation capability, so the general Web site does not need to adjust the default values for these directives. A server with a maximum of 256 concurrent requests may need to be processed to increase the value of maxclients. A machine with a smaller memory needs to reduce the maxclients value to ensure that the server does not crash. See Performance tips for more questions about tuning processes.

In Unix systems, the parent process normally runs as root for state 80 ports, while Apache-generated subprocess typically runs with a low privileged user. The user and group directives are used to set the low privileged user of the child process. A user running a subprocess must have read access to the content it serves, but must have as few permissions as possible for resources other than the content of the service.

The Maxrequestsperchild command controls how often the server kills the old process to produce a new process.

Four, the worker MPM

Overview

This multi-channel module (MPM) enables the network server to support mixed multithreaded multiple processes. Because you use threads to process requests, you can handle massive requests, and system resources are less expensive than MPM. However, it also uses multiple processes, each with multiple threads, to gain MPM stability based on process.

The most important instruction to control this MPM is to control the Threadsperchild instructions for the number of threads that each subprocess allows to establish, and the maxclients instructions that control the number of bus processes allowed.

Working mode

The number of threads that each process can hold is fixed. The server will increase or decrease the number of processes based on the load. A separate control process (the parent process) is responsible for the establishment of the child process. 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.

Apache always tries to maintain a standby (spare) or idle service thread pool. In this way, the client does not have to wait for a new thread or a new process to be established to be processed. The number of processes established during initialization is determined by the Startservers directive. The parent process then detects the total number of idle threads in all child processes and creates a new or ending subprocess that maintains the total number of idle threads within the bounds specified by Minsparethreads and maxsparethreads. Since this process is automatically adjusted, there is little need to modify the default values for these directives. The maximum number of clients that can be processed in parallel depends on the maxclients directive. The maximum number of active child processes depends on the value of MaxClients divided by Threadsperchild.

There are two instructions that set the number of active child processes and the hard limit of the number of threads per subprocess. To change this hard limit, you must completely stop the server and then start the server (direct restart is not possible), Serverlimit is the hard limit of the number of active child processes, it must be greater than or equal to maxclients divided by Threadsperchild value. Threadlimit is a hard limit on the total number of all service threads and must be greater than or equal to the Threadsperchild directive. These two instructions must appear in front of the other WORKERMPM directives.

In addition to the number of active child processes set up, there may be additional child processes in the "aborting" state but at least one of the service threads is still processing client requests until the maxclients is reached so that the process ends, although the actual number is small. This behavior can be avoided by the following methods that prohibit special child processes from being aborted:

* Set the Maxrequestsperchild to "0"

* Set Maxsparethreads and maxclients to the same value

A typical configuration for WORKERMPM is as follows:

Serverlimit 16

Startservers 2

MaxClients 150

Minsparethreads 25

Maxsparethreads 75

Threadsperchild 25

In Unix, in order to be able to bind 80 ports, the parent process is typically started as root, and then Apache establishes the subprocess and thread with the less privileged user. The user and group directives are used to set permissions on the Apache subprocess. Although a child process must have read access to the content it provides, it should give it less privilege as much as possible. In addition, unless suexec is used, the permissions set by these directives are inherited by the CGI script.

The maxrequestsperchild directive is used to control how often the server establishes a new process and ends an old process.

Five, MPM common instructions

Startservers directives

The startservers directive sets the number of child processes that are established when the server is started.

Because the number of subprocess depends on the weight of the load dynamically, it is not generally necessary to adjust this parameter.

Minspareservers directives

The minspareservers instruction sets the minimum number of idle child processes.

An idle subprocess is a child process that is not processing a request. If the current number of idle child processes is less than minspareservers, Apache will produce a new subprocess at a maximum rate of one per second.

This parameter needs to be adjusted only on very busy machines. Setting this parameter too large is usually a bad idea.

Maxspareservers directives

The maxspareservers instruction sets the maximum number of idle child processes.

An idle subprocess is a child process that is not processing a request. If there is currently an idle subprocess exceeding the maxspareservers number, the parent process kills the extra child processes.

This parameter needs to be adjusted only on very busy machines. Setting this parameter too large is usually a bad idea. If you set the value of this directive to be smaller than Minspareservers, Apache will automatically modify it to "minspareservers+1".

MaxClients directives

The maxclients directive sets the maximum number of access requests that allow simultaneous servos.

Any requests exceeding the maxclients limit will enter the waiting queue until the maximum value of the listenbacklog instruction limit is reached. Once a link is released, the request in the queue is serviced.

For MPM (that is, prefork), maxclients represents the maximum number of child processes that can be used for a servo client request, and the default value is 256. To increase this value, you must increase the serverlimit at the same time.

For thread-or mixed-type MPM (i.e. BeOS or worker), maxclients represents the maximum number of threads that can be used for a servo client request. The default value for thread-type BeOS is 50. The default value for the mixed type MPM is the result of serverlimit multiplied by (threadsperchild). Therefore, to increase the maxclients to more than 16 processes to provide, you must also increase the value of serverlimit.

Maxrequestsperchild directives

The MAXREQUESTSPERCHILD directive sets the maximum number of requests that each subprocess allows for the servo during its lifetime. Once the Maxrequestsperchild limit is reached, the child process will end. If Maxrequestsperchild is "0", the child process will never end.

Different default values

The default value on Mpm_netware and Mpm_winnt is "0".

There are two benefits to setting Maxrequestsperchild to a value other than 0:

* can prevent (accidental) memory leaks from indefinitely, thus exhausting memory.

* Give the process a finite lifetime, thereby helping to reduce the number of active processes when the server load is reduced.

Attention:

For keepalive links, only the first request is counted. In fact, it changes the behavior of each child process limiting the maximum number of links.

Threadsperchild directives

This instruction sets the number of threads established by each child process.

The child processes create these threads at startup and no longer create new threads. If you use a mpm similar to mpm_winnt with only one subprocess, this number is large enough to handle the possible peak of requests. If you use a MPM that is similar to the number of child processes that a worker has, the total number of threads owned by each child process is large enough to handle the possible peak of requests.

The default value for Mpm_winnt,threadsperchild is 64; for the other MPM is 25.

Threadlimit directives

This directive sets the Threadsperchild limit for the number of threads that can be configured per child process.

Any changes to this instruction during the reboot will be ignored, but the changes to the Threadsperchild will take effect.

Be particularly careful when using this instruction. If you set the Threadlimit to a threadsperchild that actually requires a lot of value, there will be too much shared memory to be allocated. If you set Threadlimit and threadsperchild to exceed the processing power of your system, Apache may not start, or the system will become unstable. The value of the directive should be consistent with the maximum value that Threadsperchild might achieve.

The default value for Mpm_winnt,threadlimit is 1920; for other MPM this value is 64.

Attention:

Apache has a rigid limit of "threadlimit 20000" at compile time (for mpm_winnt is "Threadlimit 15000") and cannot go beyond this limit.

Serverlimit directives

For PREFORKMPM, this instruction sets the value of the MaxClients maximum allowable configuration.

For WORKERMPM, this instruction is combined with Threadlimit to set the value of the MaxClients maximum allowable configuration. Any changes to this instruction during the reboot will be ignored, but the changes to the maxclients will take effect.

Be particularly careful when using this instruction. If you set the Serverlimit to a value that is much higher than you actually need, there will be too much shared memory allocated. If you set Serverlimit and maxclients to exceed the processing power of your system, Apache may not start, or the system will become unstable.

For PREFORKMPM, use this instruction only if you need to set the maxclients above the default value of 256. To keep the value of this directive the same as maxclients.

For WORKERMPM, this instruction is required only if you need to set the maxclients and Threadsperchild to more than 16 child processes that need to exceed the default value. Do not set the value of this directive to be higher than the number of child processes required by maxclients and Threadsperchild.

Attention:

Apache has a hard limit of "serverlimit 20000" at compile time (for preforkmpm "Serverlimit 200000"). Cannot go beyond this limit.

V. Summary

If your site needs better scalability, you can choose Worker or event threading MPM, while sites that require better stability and compatibility to accommodate some old software can use Prefork. The current version of Apache 2.4 already has a lot of optimizations for event performance. So it has changed from an experimental variant to a real usability model. Therefore, if there is no special need, we recommend the use of event mode. and the default in apache2.4 is the event mode.

This article from the "Stone Forest Blog" blog, please be sure to keep this source http://stoneking.blog.51cto.com/65035/1136820

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.