Dec 042012
Article Apache

An Apache web server running in worker multiprocessing mode forks a set of children processes to answer incoming requests from users. Each of these children processes, in turn, spawns several threads to distribute the processing load. The number of processes and threads to run can be configured to optimize the usage of the available resources.

Apache mpm worker configuration parameters

The configuration parameters that control the creation of processes and threads in mpm worker mode are:

StartServers – Set the number of children processes forked in the server initialization. If the number of requests received at a given point in time exceeds the number that can be served by the running processes, new children are forked, up to a maximum number of concurrent processes specified by the parameter ServerLimit.

ServerLimit – Set the maximum number of concurrent children processes running in the server.

ThreadsPerChild – Every child process executes the number of threads specified by this parameter.

ThreadLimit – ThreadLimit is the maximum value allowed for the ThreadsPerChild parameter. ThreadLimit can only be modified by a full stop and start of the server. On the contrary, the value of ThreadsPerChild can be modified by a warm restart.

MinSpareThreads – This parameter sets the minimum number of threads that should be idle, waiting for new requests to be processed.

MaxSpareThreads – When the number of incoming requests decreases, the server ends a number of threads as required, to ensure that the number of idle threads falls below the limited established in this parameter.

MaxClients – This parameter defines the maximum number of requests that can be concurrently served, and therefore the maximum number of active threads.

MaxRequestsPerChild – This is the number of requests that a child process will server during its lifespan. When this limit is reached, the server ends the process and creates a new process if required. This parameter can be set to zero to allow the children processes to continue running indefinitely, until the server itself is stopped.

These parameters are interrelated, and therefore there are some restrictions to the values they can be assigned:

  • ServerLimit must be greater than or equal to ( MaxClients / ThreadsPerChild )
  • MinSpareThreads and MaxSpareThreads will normally be multiples of ThreadsPerChild, although this is not mandatory
  • ThreadsPerChild must be less than or equal to ThreadLimit

Configuration recommendations

Every web server is different, and there are no generic rules valid for all of them. Nevertheless, we can advise that the number of processes set in ServerLimit be similar to the number of processors in the server: The default value of ThreadsPerChild in mpm worker is 25. With this value, a server with four processors could serve a total of 100 concurrent requests. If the average load of the server exceeds this value, several combinations can be tried:

– Increment ThreadsPerChild up to 64, the default value for ThreadLimit

– Increment ServerLimit up to 16, the default value for this parameter.

With this, the server can handle up to 16*64=1024 concurrent requests, if the available de RAM, CPU and bandwidth resources allow it.

 Posted by at 4:43 pm

 Leave a Reply