In prefork mode, 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, 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 have difficulty in thread debugging, it is easier to debug.
In worker mode, 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 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 all its threads ". because threads share memory space, a program must be recognized by the system as "Every thread is safe" during runtime ".
The prefork method is faster than worker. However, it requires more cpu and memory resources than woker.
View the current working mode:
Apachectl-l
Two modes configuration file + description:
Perfork mode:
Copy codeThe Code is as follows: <IfModule mpm_prefork_module>
ServerLimit 2000
# Set this option if the number of connections is greater than 256. 20000 is the maximum value of ServerLimit.
StartServers 5
# Number of child processes created during initialization. Prefork is 5 by default.
MinSpareServers 10
# Minimum number of idle Processes
MaxSpareServers 15
# Maximum number of idle Processes
MaxClients 1000
# Maximum number of concurrent client connections
MaxRequestsPerChild 10000
# Control the server's frequency of killing old processes to generate new processes
# Setting 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 the process, which helps reduce the number of active processes when server load is reduced.
</IfModule>
Worker mode:
Copy codeThe Code is as follows: <IfModule mpm_worker_module>
StartServers 3
# Number of child processes created during initialization
MaxClients 2000
# Maximum number of parallel processing tasks. Maximum number of sub-processes = MaxClients/ThreadsPerChild
ServerLimit 25
# This command is required only when you need to set MaxClients and ThreadsPerChild to 16 sub-processes that exceed the default value. Do not set the value of this command to a greater number of sub-processes than MaxClients and ThreadsPerChild.
MinSpareThreads 50
# Minimum number of empty threads
Maxsparethread S 200
# Maximum number of Idle threads
ThreadLimit 200
# This command sets the maximum number of threads that can be configured for each sub-process. The value of this command should be consistent with the maximum value that ThreadsPerChild may reach.
ThreadsPerChild 100
# Number of service threads created by sub-Processes
MaxRequestsPerChild 0
# Set 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.
</IfModule>
Working Mode Modification Method:
Recompile the specified working mode (prefork by default)
Copy codeThe Code is as follows:./configure -- with-mpm = worker
Note:
After you change the parameters related to the working mode, you must disable the apache service and restart the service.
Directly starting with restart will be invalid.