The MPM modules allow you to use threads or even move apache to a different OS
We have three different MPMs and we can activate one module only. Alright let’s talk about the 3 MPMs
- The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.
- The event MPM is threaded like the Worker MPM, but is designed to allow more requests to be served simultaneously by passing off some processing work to supporting threads, freeing up the main threads to work on new requests.
- The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork’s threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.
In apache 2.4 the prefork MPM is the default module , the aim of this lesson is to give you an overview about different MPMs but which one to enable and configure is up to you depending on your needs.
Alright , now let’s talk about MPM directives to understand it together before we use them in our configuration
StartServers (Prefork, Event, Worker MPM)
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
MinSpareServers (Prefork MPM)
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 spareservers idle then specified by this value, then the parent process creates new children at a maximum rate of 1 per second. Setting this parameter to a large number is almost always a bad idea.
MaxSpareServers (Prefork MPM)
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. If there are more idle processes than this number, then they are terminated.
Unless your website is extremely busy, this number should not be set too high, since idle processes consume valuable resources.
ServerLimit (Prefork, Event, Worker MPM)
When using Prefork MPM ServerLimit is only used in case you need to set MaxRequestWorkers higher than 256 (default). In this case you should match the value you have set for MaxRequestWorkers, but you should not set the value of this directive any higher than what you might want to set MaxRequestWorkers to.
For the worker and event MPMs, this directive in combination with ThreadLimit sets the maximum configured value for MaxRequestWorkers for the lifetime of the Apache httpd process.
For the event MPM, this directive also defines how many old server processes may keep running and finish processing open connections.
ThreadLimit (Event, Worker MPM)
This directive sets the maximum configured value for ThreadsPerChild for the lifetime of the Apache httpd process. Any attempts to change this directive during a restart will be ignored, but ThreadsPerChild can be modified during a restart up to the value of this directive.
Special care must be taken when using this directive. If ThreadLimit is set to a value much higher than ThreadsPerChild, extra unused shared memory will be allocated. If both ThreadLimit and ThreadsPerChild are set to values higher than the system can handle, Apache httpd may not start or the system may become unstable.
Do not set the value of this directive any higher than your greatest predicted setting of ThreadsPerChild for the current run of Apache httpd.
ThreadsPerChild (Event, Worker MPM)
This directive sets the number of threads created by each child process. The child creates these threads at startup and never creates more. If using an MPM like mpm_winnt, where there is only one child process, this number should be high enough to handle the entire load of the server. If using an MPM like worker, where there are multiple child processes, the total number of threads should be high enough to handle the common load on the server.
MaxRequestWorkers / MaxClients (Prefork, Event, Worker MPM)
MaxRequestWorkers was called MaxClients before Apache version 2.3.13. However, the old name is still supported. It sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxRequestWorkers 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.
If this value is set too low, connections sent to queue eventually time-out; however, if this directive is set too high, it causes the memory to start swapping.
For non-threaded servers (i.e., prefork), MaxRequestWorkers translates into 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.
MaxRequestWorkers and ServerLimit should have equal or near equal values with MaxRequestWorkers never exceeding ServerLimit. For servers under high load this value should be increased.
MaxConnectionsPerChild (Prefork, Event, Worker MPM)
MaxConnectionsPerChild sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.
Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.