Apache two modes of operation: (mainstream) Prefork/worker
Prefork mode: Default this mode (more commonly used)
Higher efficiency, but larger than worker use of memory
This multi-path processing module (MPM) implements a non-threaded, pre-derived Web server that works like apache1.3. It applies to no thread-safe libraries,
Systems that need to avoid threading compatibility issues. It requires the best mpm to separate each request from each other, so that a problem with one request does not affect other requests.
This MPM has a strong self-tuning capability and requires only a few configuration-specific adjustments. The most important thing is to set the maxclients to a value large enough to handle
A potential request spike, at the same time, cannot be too large to use more memory than the size of physical memory
Check which mode is available by
Httpd-l
If there is a prefork.c, it is represented as Prefork mode, and similarly, if there is worker.c, the worker mode
Configuration file: In httpd.conf
<ifmodule prefork.c>
#
#
#
</IfModule>
MaxClients #默认的最大线程数, if you want a larger value, add serverlimit 20000, this must be placed before the other instructions to take effect,
If it is still larger, you will have to recompile Apache to limit the number of client maximum access requests at the same time (and the number of individual processes). Any more than
MaxClients Limit requests will enter the waiting queue, and once a link is released, the request in the queue will be serviced
Startservers 5 #指定服务器在启动时建立的子进程数量, default is 5
Minspareservers 5 #指定空闲子进程的最小数量, the default is 5, if the number of currently idle child processes is less than minspareservers, then
Apache will produce new sub-processes at a maximum speed of one second. This parameter should not be too large
Maxspareservers 20 # Configures the maximum number of idle child processes, by default 20, if there is currently more than maxspareservers number of idle child processes,
The parent process then kills the extra child process. This parameter should not be too large,
Maxrequestsperchild 4000 #每个子进程在其生存期内允许伺服的最大请求数量, after reaching the limit of Maxrequestsperchild,
The child process will end. If set to 0, the child process will never end.
setting to greater than 0 has benefits:
1. The memory leak can be prevented indefinitely, thus exhausting memory.
2. Give the process a limited lifespan, thus helping to reduce the number of active processes when the server load is reduced.
Worker mode (multi-threading module that supports mixed multithreaded multi-process)
With multiple child processes, each child process has multiple threads. Each thread can only maintain one connection at a certain time. Generally speaking,
On a high-traffic HTTP server, the worker mpm is a better choice because the worker MPM uses much less memory than Prefork MPM.
But the worker MPM also has shortcomings, such as a thread crashes, and the entire process "hangs" with any of its threads,
Because a thread is a shared memory space, a program must be recognized by the system as "each thread is secure" at run time
Configuration file: In httpd.conf
<ifmodule prefork.c>
#
#
#
</IfModule>
Serverlimit #服务器允许配置的进程上限, this directive is used in conjunction with Threadlimit 50.
Threadlimit #每个子进程可配置的线程数上限, this instruction configures the number of threads that can be configured per child process
Startservers 3 #服务器启动时建立的子进程数.
Threadsperchild #每个子进程建立常驻的线程数.
General Configuration Method:
Threadlimit >= Threadsperchild
MaxClients = Minsparethreads+threadsperchild
Hard limit:
The two instructions for Serverlimi and threadlimit determine the number of active child processes and the hard limit of the number of threads per child process.
To change this hard limit you must completely stop the server and then start the server (a direct restart is not possible).
Apache has a hard limit in compiling serverlimit, and you can't go beyond this limit.
Prefork MPM Max is "Serverlimit 200000"
The maximum number of other MPM (including work MPM) is "Serverlimit 20000
Apache has a hard limit in compiling threadlimit, and you can't go beyond this limit.
Mpm_winnt is "Threadlimit 15000"
Other MPM (including work prefork) are "Threadlimit 20000
Attention
Be especially careful when using serverlimit and Threadlimit.
If the Serverlimit and Threadlimit are configured to a higher value than is actually required,
There will be too much shared memory to be allocated. When configured to exceed the system's processing power, Apache may not boot, or the system will become unstable.
Apache Working mode