Two working modes of the Apache MPM module (multi-task and high concurrency)

Source: Internet
Author: User

Apache processes a large number of concurrent connections at the same time, thanks to the MPM module of Apache.

MPM processes network connections independently into modules, so that different platforms can use different concurrency models to achieve optimal results.

Idle sub-process: the sub-process that is not processing the request.

1. prefork. C Module (a non-thread-type pre-derived MPM)
Prefork MPM uses multiple sub-processes. Each sub-process has only one thread. Each process can maintain only one connection at a specified time. On most platforms, the prefork MPM is more efficient than the worker mpm, but the memory usage is much larger. Prefork's wireless program design will be more advantageous in some cases than worker: it can use third-party modules that do not handle thread security well, and for platforms that are difficult to debug threads, it is easier to debug.

Serverlimit 20000

Startservers 5

Minspareservers 5

Maxspareservers 10

Maxclients 1000

Maxrequestsperchild 0

Serverlimit 2000

// The default maxclient has a maximum of 256 threads. If you want to configure a larger value, add the serverlimit parameter. 20000 is the maximum value of serverlimit. If you need more, you must compile Apache without re-compiling Apache.

Prerequisite: It must be placed before other instructions.

Startservers 5

// Specify the number of sub-processes created when the server starts. The default value of prefork is 5.

Minspareservers 5

// Specify the minimum number of idle sub-processes. The default value is 5. If the number of idle sub-processes is less than minspareservers, Apache will generate a new sub-process at a maximum speed per second. Do not set this parameter too large.

Maxspareservers 10

// Configure the maximum number of idle sub-processes. The default value is 10. If there are idle sub-processes that exceed the number of maxspareservers, the parent process will kill the redundant sub-processes. Do not set this parameter too large. If you set the value of this command to be smaller than minspareservers, Apache will automatically change it to "minspareservers + 1 ".

Maxclients 256

// Limit the maximum number of client access requests (number of concurrent threads of a single process) at the same time. The default value is 256. Any request that exceeds the limit of maxclients will enter the waiting queue. Once a link is released, the request in the queue will be served. To increase this value, you must increase serverlimit at the same time.

Maxrequestsperchild 10000

// Each sub-process allows the maximum number of requests from the servo within its lifetime. The default value is 10000. After reaching the limit of maxrequestsperchild, the sub-process will end. If maxrequestsperchild is "0", the child process will never end.

Configuring maxrequestsperchild to a non-zero value has two advantages:

1. It can prevent (accidental) infinite Memory leakage and thus exhaust the memory.

2. A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.

Working Method:

A separate control process (parent process) is responsible for generating child processes that are used to listen for requests and respond. Apache always tries to keep some standby (spare) or idle sub-processes to meet the upcoming requests. In this way, the client does not have to wait for the sub-process to generate before obtaining the service. In Unix systems, the parent process is usually run as the root to bind port 80, while the sub-process generated by Apache is usually run as a low-privilege user. User and group commands are used to configure low-privilege users of sub-processes. A user running a sub-process must have the read permission on the content of the sub-process, but must have as few permissions as possible for resources other than the service content.
2. Worker. C Module (supporting multi-thread multi-process multi-channel processing module)

Worker MPM uses multiple sub-processes, each of which has multiple threads. Each thread can maintain only one connection at a specified time. Generally, on a high-traffic HTTP server, worker MPM is a good choice, because the memory usage of worker MPM is much lower than that of prefork MPM. However, the worker MPM is also imperfect. If a thread crashes, the whole process will "die" together with any of its threads ". because threads share memory space, a program must be recognized by the system as "Every thread is safe" during running ".

Serverlimit 50

Threadlimit 200

Startservers 5

Maxclients 5000

Minsparethreads 25

Maxsparethread S 500

Threadsperchild 100

Maxrequestsperchild 0

Serverlimit 16

// The maximum number of processes allowed by the server. This command is used in combination with threadlimit to configure the maximum allowed value of maxclients. Any changes to this command during the restart will be ignored, but the changes to maxclients will take effect.

Threadlimit 64

// The maximum number of threads that can be configured for each sub-process. This command configures the maximum number of threads that can be configured for each sub-process. Any change to this command during the restart will be ignored, but the change to threadsperchild will take effect. The default value is "64 ".

Startservers 3

// Number of sub-processes created when the server starts. The default value is "3 ".

Minsparethreads 75

// The minimum number of Idle threads. The default value is "75 ". This MPM will monitor the number of Idle threads based on the entire server. If the total number of Idle threads on the server is too small, the child process will generate a new idle thread.

Maxsparethread s 250

// Configure the maximum number of Idle threads. The default value is 250 ". This MPM will monitor the number of Idle threads based on the entire server. If the total number of Idle threads in the server is too large, the child process will kill the redundant Idle threads. The value range of maxsparethreads is limited. Apache automatically fixes your configuration value according to the following restrictions: worker requires the sum of minsparethreads and threadsperchild

Maxclients 400

// The maximum number of access requests (the maximum number of threads) that can be simultaneously servo ). Any request that exceeds the maxclients limit will enter the waiting queue. The default value is "400", 16 (serverlimit) multiplied by 25 (threadsperchild. Therefore, to add maxclients, you must add the serverlimit value at the same time.

Threadsperchild 25

// The number of resident execution threads created by each sub-process. The default value is 25. After these threads are created at startup, the child process will no longer create new threads.

Maxrequestsperchild 0

// Configure the maximum number of requests allowed by the servo for each sub-process during its lifetime. When the limit of maxrequestsperchild is reached, the sub-process will end. If maxrequestsperchild is "0", the child process will never end.

Configuring maxrequestsperchild to a non-zero value has two advantages:

1. It can prevent (accidental) infinite Memory leakage and thus exhaust the memory.

2. A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.

Note:

For keepalive links, only the first request is counted. In fact, he changed the behavior of each sub-process to limit the maximum number of connections.

Working Method:

The number of threads that each process can possess is fixed. The server increases or reduces the number of processes based on the load. A separate control process (parent process) is responsible for establishing 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. Apache always tries to maintain a standby (spare) or idle service thread pool. In this way, the client can be processed without waiting for the creation of a new thread or process. In UNIX, in order to be able to bind port 80, the parent process is generally started as root, and then Apache creates sub-processes and threads with lower permissions. The user and group commands are used to configure the permissions of Apache sub-processes. Although the sub-process must
The provided content has read permissions, but should be given as few privileges as possible. In addition, unless suexec is used, the permissions configured for these commands will be inherited by CGI scripts.
Formula:

Threadlimit> = threadsperchild

Maxclients = minsparethreads + threadsperchild
Hard limit:
The serverlimi and threadlimit commands determine the number of active sub-processes and the number of threads in each sub-process. To change this hard limit, you must completely stop the server and then start the server (you cannot restart the server directly ).
Apache has a hard limit in compiling serverlimit. You cannot exceed this limit.

The maximum value of prefork MPM is "serverlimit 200000"

The maximum value of other mpm (including work MPM) is "serverlimit 20000 ".
Apache has a hard limit in compiling threadlimit. You cannot exceed this limit.

Mpm_winnt is "threadlimit 15000"

Other mpm (including work prefork) is "threadlimit 20000
Note:

Be careful when using serverlimit and threadlimit. If you configure serverlimit and threadlimit to a value that is much higher than actually needed, too much shared memory will be allocated. When the configuration exceeds the processing capability of the system, Apache may fail to start or the system may become unstable.


An article that loads an Apache learning route: http://www.cnblogs.com/steven_oyj/archive/2010/05/29/1747028.html

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.