inside the mind of a linux admin

apache MPMs


What are Multi-Processing Modules (MPM)?
Prefork vs Worker

Multi-Processing Modules (MPM) extend the modular design of Apache technology used in the Covalent Enterprise Ready Server. These modules perform the most basic functions of a web server: binding to network ports on the machine, accepting requests, and dispatching children to handle the requests. MPMs allow Apache technology to cleanly and efficiently support a wide variety of operating systems.

With MPMs, the server can be better customized for the needs of the particular site. For example, sites that need a great deal of scalability can choose to use a threaded model such as the Worker MPM, while sites requiring stability or compatibility with older software can use the Prefork MPM.

MPMs must be compiled into the server. The Covalent Enterprise Ready Server for UNIX systems is shipped with two different pre-compiled versions of the Apache 2.0 server: the Prefork MPM and the Worker MPM.

Prefork MPM

This model implements a non-threaded, pre-forking server. It handles requests in a manner very similar to the default behaviour of Apache 1.3. This server is very robust. For example:

Prefork MPM

StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0

Or:

Worker MPM
This model implements a hybrid multi-process multi-threaded server for systems that support POSIX threads. Each process has a fixed number of threads. When a request is received, it is passed to a worker thread for processing. The server adjusts to changes in its load by increasing or decreasing the number of processes. This server scales very easily but emphasizes robustness. For example:

StartServers 3
MaxClients 8
MinSpareThreads 5
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0

StartServers
The number of server processes to start initially. You may need to increase this value on a very active system.

MaxClients
This sets a limit on the total number of server processes running on this system-that is, a limit on the number of clients who can simultaneously connect. When this limit is reached, subsequent clients will be unable to access the server. Avoid setting it too low.
The MaxClients setting should correlate with the resources available to the host system. You should set this value according to the memory available on your system. If it is set too high, it will induce swapping, which can be catastrophic for your system performance.

MaxRequestsPerChild
This controls the number of requests each server process is allowed to process before it is forced to terminate. The server exits to avoid problems after prolonged use, such as memory leaks or other resource issues. A setting of 0 (zero) means the server process is allowed to handle an unlimited number of requests.

MinSpareServers
The minimum number of server processes to be kept as spares. If there are fewer than the specified number of servers idle, Apache creates enough new processes to reach the minimum. If this number is set to low, your server response will be very slow as new server processes will have to be created when the server load is high.
This directive is only used by the Prefork MPM.

MaxSpareServers
The maximum number of idle server processes to be kept as spares. If there are more than the specified number of servers idle, Apache terminates the additional processes. Increasing this value will allow the server to respond more quickly to changing load conditions. However, note that increasing the number of server processes also increases the load on the host system.
This directive is only used by the Prefork MPM.

MinSpareThreads
Similar to the above, this defines the minimum number of worker threads to be kept as spares. If the number of idle worker threads drops below this number, Apache creates another new server process to handle the load.
Changing this value effects the threads in all worker processes.
This directive is only used by the Worker MPM.

MaxSpareThreads

Similar to the above, this defines the maximum number of worker threads to be kept as spares. If there are more than the specified number of worker threads idle, Apache terminates the process running those threads.
Changing this value effects the threads in all worker processes.
This directive is only used by the Worker MPM.

ThreadsPerChild
This defines the number of worker threads created in each server process. This is a constant value. If you set this to 25, the server will spawn 25 threads in each server process it creates.

This directive is used by the Worker MPM

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.