In apache you can enable a maximum of one MPM (Multi-Processing Modules) and any number of other modules.
The available MPMs are:
core: Core Apache HTTP Server features that are always available
mpm_common: A collection of directives that are implemented by more than one multi-processing module (MPM)
beos: This Multi-Processing Module is optimized for BeOS.
leader: An experimental variant of the standard worker MPM
mpm_netware: Multi-Processing Module implementing an exclusively threaded web server optimized for Novell NetWare
mpmt_os2: Hybrid multi-process, multi-threaded MPM for OS/2
perchild: Multi-Processing Module allowing for daemon processes serving requests to be assigned a variety of different userids
prefork: Implements a non-threaded, pre-forking web server
threadpool: Yet another experimental variant of the standard worker MPM
mpm_winnt: This Multi-Processing Module is optimized for Windows NT.
worker: Multi-Processing Module implementing a hybrid multi-threaded multi-process web server
I have been using prefork because
1. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. I use PHP throughout.
2. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
Here I discuss the functioning of the prefork MPM and the various directives used to control its behavior. The description of these directives has been taken form the apache2.0 documentation.
prefork.c
This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
This MPM is very self-regulating, so it is rarely necessary to adjust its configuration directives. Most important is that MaxClients be big enough to handle as many simultaneous requests as you expect to receive, but small enough to assure that there is enough physical RAM for all processes.
A single control process is responsible for launching child processes which listen for connections and serve them when they arrive. Apache always tries to maintain several spare or idle server processes, which stand ready to serve incoming requests. In this way, clients do not need to wait for a new child processes to be forked before their requests can be served.
MaxSpareServers: The MaxSpareServers directive sets the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes.
Tuning of this parameter should only be necessary on very busy sites. Setting this parameter to a large number is almost always a bad idea. If you are trying to set the value lower than MinSpareServers, Apache will automatically adjust it to MinSpareServers + 1.
MinSpareServers:The MinSpareServers directive sets the desired minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than MinSpareServers idle, then the parent process creates new children at a maximum rate of 1 per second.
Tuning of this parameter should only be necessary on very busy sites. Setting this parameter to a large number is almost always a bad idea.
MaxClients: For non-threaded servers (i.e., prefork), MaxClients is the maximum number of child processes that will be launched to serve requests. The default value is 256; to increase it, you must also raise ServerLimit.
Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process is freed at the end of a different request, the connection will then be serviced.
ServerLimit: For the prefork MPM, this directive sets the maximum configured value for MaxClients for the lifetime of the Apache process.
If ServerLimit is set to a value much higher than necessary, extra, unused shared memory will be allocated. If both ServerLimit and MaxClients are set to values higher than the system can handle, Apache may not start or the system may become unstable. Do not set the value of this directive any higher than what you might want to set MaxClients to.
There is a hard limit of ServerLimit 20000 compiled into the server. This is intended to avoid nasty effects caused by typos.
StartServers: The StartServers directive sets the number of child server processes created on startup. As the number of processes is dynamically controlled depending on the load, there is usually little reason to adjust this parameter.
MaxRequestsPerChild: The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire.
Setting MaxRequestsPerChild to a non-zero limit has two beneficial effects:
* it limits the amount of memory that process can consume by (accidental) memory leakage;
* by giving processes a finite lifetime, it helps reduce the number of processes when the server load reduces.
For KeepAlive requests, only the first request is counted towards this limit. In effect, it changes the behavior to limit the number of connections per child.













0 Responses to “How does prefork.c work?”
Leave a Reply