4.1.1 Process architecture of HTTP Server (UNIX version and prefork MPM module)
- Organization of this subsection
(1) Process architecture
The following figure shows the architecture of HTTP Server process.
|
|
When you start HTTP Server, the control process starts. The control process starts the server process to process the request, and monitors the server process operations. Initially, the control process generates the number of server processes specified in the StartServers directive. Later, the control process increases or decreases the number of server processes based on values specified in the MinSpareServers and MaxSpareServers directives. The MaxClients directive specifies the maximum value for number of server processes. The control process manages the increase or decrease in the number of server processes. This process is called maintenance.
The OS receives the TCP connection of client, from the IP address and port specified in the Listen directive, and reserves the connection in the Listen queue of OS. You can specify the size of the Listen queue in the ListenBacklog directive. The TCP connection that cannot be stored in the Listen queue is not established. One of the server processes picks up a TCP connection stored in the Listen queue and performs the processing.
One server process accepts a single TCP connection and performs the processing. One server process ends after processing the number of HTTP requests specified in the MaxRequestsPerChild directive. In such a case, the control process generates a new server process and continues processing.
The control process is operated by user and group permissions with which HTTP Server is started. The server process is operated with user and group permissions specified in the User and Group directives. For both, control processes and server processes, the process name (execution program name) is httpsd. The process ID of the control process is output to the file specified in the PidFile directive.
(2) Transition of number of processes
To avoid the load concentration on the server, the maintenance generates 2n-1 server processes (n is the number of continuous maintenance executions, where n = 6 if number of processes is more than or equal to 6) in one second. The server processes are generated until the number of waiting processes specified in the MinSpareServers directive can be processed, or the number of all processes equals the number specified in the MaxClients directive. When 8 or more server processes are generated in a single maintenance, an error is logged (info level).
If the request processing ends, the state of the server process changes to the waiting state. If processes in the waiting state increase, only the number of processes specified in the MaxSpareServers directive remains during maintenance and other server processes are terminated.
(a) Notes
-
Specify a large value in the StartServers directive, in the cases such as you must process a large number of requests immediately after starting or restarting the Web server.
-
The number of the processes generated after the Web server starts are controlled depending upon the MaxSpareServers and the MinSpareServers directives, and hence the specified value in the StartServers directive becomes irrelevant (except when the HWSKeepStartServers directive is set to On). Specify the MinSpareServers and the MaxSpareServers directives for preparing the processes in waiting state such that they can handle the sudden increase in number of requests. If error logging (info level) occurs frequently in the maintenance process, adjust the values of these directives to increase the number of waiting processes.
-
If many server processes are always kept in the waiting state, concurrent connection requests from many clients can be received. However, you need to take precaution because that much server resources will be consumed.
-
When the CPU is overloaded with CGI programs, you need to set a small value in the MaxClients directive to stop receiving requests. If all the processes specified in the MaxClients directive are being processed, the requests are held in queue depending upon the ListenBacklog directive specification.
-
A server process ends after processing the number of requests specified in the MaxRequestsPerChild directive. However, if the MaxRequestsPerChild directive is set to 0, the server process does not end with the request process count. If there are chances of memory leakage in the application programs created by the end-user, the specification of the MaxRequestsPerChild directive is applied.
-
When an abnormal termination signal is sent to the server process (even when a failure occurs in API connection module), the process outputs information about the abnormal termination to the error log (notice level). An error log of notice level is output regardless of the LogLevel directive specification.
-
When you want to always keep the number of server processes specified in the StartServers directive running regardless of the number specified in the MaxSpareServers and MinSpareServers directives, set the HWSKeepStartServers directive to On. If the server process count is less than the number specified in the StartServers directive, the Web server generates new processes to arrive at the specified number.
-
If you stop HTTP Server, the files specified in the PidFile directive are deleted. However, when HTTP Server is forcibly stopped by something other than the program, for example, the machine is shut down without stopping HTTP Server, the files specified in the PidFile directive remain undeleted. Starting HTTP Server again might result in a failure. If the files specified in the PidFile directive are present while HTTP Server is not running, delete the files before restarting HTTP Server.
(b) Example of transition of number of processes
The following figure shows an example for the transition of number of processes when the specification of HWSKeepStartServers is Off.
-
Specified values of directives (when HWSKeepStartServers is set to Off)
LoadModule mpm_prefork_module libexec/mod_mpm_prefork.so StartServers 8 MaxSpareServers 10 MinSpareServers 5 MaxClients 15 HWSKeepStartServers Off MaxRequestsPerChild 10000 KeepAlive Off
Figure 4‒2: An example of transition of number of processes (when HWSKeepStartServers is set to Off)
The following figure shows an example of transition of number of processes when HWSKeepStartServers is set to On.
-
Specified values of directives (when HWSKeepStartServers is set to On)
LoadModule mpm_prefork_module libexec/mod_mpm_prefork.so StartServers 8 MaxSpareServers 10 MinSpareServers 5 MaxClients 15 HWSKeepStartServers On MaxRequestsPerChild 10000 KeepAlive Off
Figure 4‒3: An example of transition of number of processes (when HWSKeepStartServers is set to On)