Two working modes of the Apache MPM module (prefork and worker)

Source: Internet
Author: User

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
Multiple Sub-processes are used. Each sub-process has only one thread. Each process can maintain only one connection at a specified time. On most platforms, prefork MPM is more efficient than worker

MPM is high, 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
It is easier to debug platforms that are difficult to debug threads.

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 the number of maxspareservers exceeds
The parent process will kill the redundant child process. Do not set this parameter too large. If you set the value of this command to a smaller value than minspareservers, Apache will automatically
Modify 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 are used 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, a parent process is usually run as a root
Port 80, and
Sub-processes generated by Apache are generally run by a low-privilege user. User and group commands are used to configure low-privilege users of sub-processes. The user who runs the sub-process must have
Read Permission. However, you 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
Multiple Sub-processes are used. Each sub-process 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 the worker MPM is much lower than that of the prefork MPM. However, 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 as "every
All threads are secure ".

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. Assume that
The total number of Idle threads in the server is too large, and the child process will kill the redundant Idle threads. The value range of maxsparethreads is limited. Apache automatically fixes your configuration according to the following restrictions:
Value: The worker must be greater than or equal to minsparethreads plus the sum of 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, you must add
Serverlimit value.

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
The number of threadsperchild service threads and a listening thread. The listening thread listens for access requests and sends them to the service thread for processing and response. Apache always tries to maintain a backup
Use (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, to bind port 80

Start as root. 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.

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.