How to determine the working mode of Apache server

How can I know what working mechanism the current apache2 uses? We can use the httpd -l command to list all modules of apache and know how it works:

 

prefork working mode 

If httpd -l lists prefork.c. It means prefork working mode. As shown below:
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c

This shows that the current way apache2 works is prefork

 

For apache in prefork working mode, its setting in httpd.conf is

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000

ServerLimit
's default MaxClient maximum is 256 threads. If you want to set a larger value, just add the ServerLimit parameter. 20000 is the maximum value of the ServerLimit parameter.
If you need to make it larger, you must compile apache. Previously, there was no need to recompile Apache.
Prerequisite for taking effect: must be placed in front of other instructions

StartServers
specifies the number of child processes created when the server starts. Prefork defaults to 5.

MinSpareServers
specifies the minimum number of idle child processes, the default is 5. If the current number of idle child processes is less than MinSpareServers,
Apache will spawn new child processes at a maximum rate of one per second. Do not set this parameter too large.

MaxSpareServers
sets the maximum number of idle child processes, the default is 10. If there are currently more than MaxSpareServers idle child processes, the parent process will kill the excess child processes.
Do not set this parameter too large. If you set the value of this directive to be smaller than MinSpareServers, Apache will automatically modify it to "MinSpareServers+1".

MaxClients
limits the maximum number of client access requests at the same time (number of concurrent threads in a single process), and the default is 256. Any requests that exceed the MaxClients limit will enter the waiting queue, and once a connection is released,
the requests in the queue will be serviced. To increase this value, you must also increase ServerLimit.

MaxRequestsPerChild
The maximum number of requests allowed to be served by each child process during its lifetime. The default is 10000. After reaching the limit of MaxRequestsPerChild, the child process will end.
If MaxRequestsPerChild is "0", the child process will never end. Setting MaxRequestsPerChild to a non-zero value has two benefits:
1. It prevents (accidental) memory leaks from proceeding indefinitely and thus exhausting memory.
2. Give processes a limited lifespan, which helps reduce the number of active processes when the server load is reduced.


According to the previous settings, in this working mode, 8 httpd processes will be started after the server starts (a total of 9 including the parent process, which can be seen through the ps -ax|grep httpd command).
When a user connects, Apache will use an idle process to serve the connection, and the parent process will fork (copy) a child process.
Until the number of idle processes in memory reaches MaxSpareServers. This mode is for compatibility with some older versions of programs. Default compile-time options.

 

worker working mode

If httpd -l lists worker.c, similar to the following, it means that the worker working mode is

Compiled in modules:
  core.c
  worker.c
  http_core.c
  mod_so.c

The configuration file at this time is as follows:

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0

StartServers
The number of child processes created when the server starts. The default value is "3".

MaxClients
allows the maximum number of access requests to be served simultaneously (the maximum number of threads). Any request exceeding the MaxClients limit will enter the waiting queue. The default value is "400",
the result of 16 (ServerLimit) times 25 (ThreadsPerChild). Therefore, when you want to increase MaxClients, you must also increase the value of ServerLimit.

MinSpareThreads
minimum number of idle threads, the default value is "75". This MPM will monitor the number of idle threads on an entire server basis. If the total number of idle threads in the server is too few, the child process will generate new idle threads.

MaxSpareThreads
sets the maximum number of idle threads. The default value is "250". This MPM will monitor the number of idle threads on an entire server basis. If the total number of idle threads in the server is too large, the child process will kill the excess idle threads.
The value range of MaxSpareThreads is limited. Apache will automatically correct the value you set according to the following restrictions:
The worker requires it to be greater than or equal to the sum of MinSpareThreads plus ThreadsPerChild.

ThreadsPerChild
The number of resident execution threads established by each child process. The default value is 25. The child process will no longer create new threads after establishing these threads at startup.

MaxRequestsPerChild
sets the maximum number of requests that each child process is allowed to serve during its lifetime. After reaching the MaxRequestsPerChild limit, the child process will end. If MaxRequestsPerChild is "0", the child process will never end. Setting MaxRequestsPerChild to a non-zero value has two benefits:
1. It prevents (accidental) memory leaks from proceeding indefinitely and thus exhausting memory.
2. Give processes a limited lifespan, which helps reduce the number of active processes when the server load is reduced.
Note that for KeepAlive connections, only the first request is counted. In fact, it changes the behavior of limiting the maximum number of links per child process.

This mode uses threads to monitor client connections. When a new client connects, one of the idle threads accepts the connection.
The server starts two processes at startup, and the number of threads generated by each process is fixed (determined by ThreadsPerChild), so there are 50 threads at startup.
When 50 threads are not enough, the server automatically forks a process and generates 25 more threads.

 

See:

Apache server optimization mode setting
http://www.phpq.net/apache/apache-server-optimization.html

Apache2.0 prefork and worker module performance tuning
http://blog.csdn.net/wenbingcai/archive/2009/05/18/4197557.aspx

Apache's prefork and worker working modes
http://hi.baidu.com/%C7%E0%B4%BA%B5%C4%BA%E3%D0%C4/blog/item/07d314a4aba0eb98d04358fe.html

Apache's prefork mode and worker mode
http://www.ccvita.com/339.html

CentOS+Apache+Mysql+Php installation and optimization configuration notes
http://liang831002.blog.51cto.com/188904/88422

Guess you like

Origin blog.csdn.net/ghj1976/article/details/6128779