/Apache HTTP Server

Apache MPM event

Description: A variant of the worker MPM with the goal of consuming threads only for connections with active processing
Status: MPM
ModuleIdentifier: mpm_event_module
SourceFile: event.c




Relationship with the Worker MPM



How it Works




Async connections


While sending the response to the client, it might happen that the TCP write buffer fills up because the connection is too slow. Usually in this case a write() to the socket returns EWOULDBLOCK or EAGAIN, to become writable again after an idle time. The worker holding the socket might be able to offload the waiting task to the listener thread, that in turn will re-assign it to the first idle worker thread available once an event will be raised for the socket (for example, "the socket is now writable"). Please check the Limitations section for more information.
Keep Alive handling is the most basic improvement from the worker MPM. Once a worker thread finishes to flush the response to the client, it can offload the socket handling to the listener thread, that in turns will wait for any event from the OS, like "the socket is readable". If any new request comes from the client, then the listener will forward it to the first worker thread available. Conversely, if the KeepAliveTimeout occurs then the socket will be closed by the listener. In this way the worker threads are not responsible for idle sockets and they can be re-used to serve other requests.
Sometimes the MPM needs to perform a lingering close, namely sending back an early error to the client while it is still transmitting data to httpd. Sending the response and then closing the connection immediately is not the correct thing to do since the client (still trying to send the rest of the request) would get a connection reset and could not read the httpd's response. The lingering close is time bounded but it can take relatively long time, so it's offloaded to a worker thread (including the shutdown hooks and real socket close). From 2.4.28 onward this is also the case when connections finally timeout (the listener thread never handles connections besides waiting for and dispatching their events).

These improvements are valid for both HTTP/HTTPS connections.

Graceful process termination and Scoreboard usage

This mpm showed some scalability bottlenecks in the past leading to the following error: "scoreboard is full, not at MaxRequestWorkers". MaxRequestWorkers limits the number of simultaneous requests that will be served at any given time and also the number of allowed processes (MaxRequestWorkers / ThreadsPerChild), meanwhile the Scoreboard is a representation of all the running processes and the status of their worker threads. If the scoreboard is full (so all the threads have a state that is not idle) but the number of active requests served is not MaxRequestWorkers, it means that some of them are blocking new requests that could be served but that are queued instead (up to the limit imposed by ListenBacklog). Most of the times the threads are stuck in the Graceful state, namely they are waiting to finish their work with a TCP connection to safely terminate and free up a scoreboard slot (for example handling long running requests, slow clients or connections with keep-alive enabled). Two scenarios are very common:

  • During a graceful restart. The parent process signals all its children to complete their work and terminate, while it reloads the config and forks new processes. If the old children keep running for a while before stopping, the scoreboard will be partially occupied until their slots are freed.
  • When the server load goes down in a way that causes httpd to stop some processes (for example due to MaxSpareThreads). This is particularly problematic because when the load increases again, httpd will try to start new processes. If the pattern repeats, the number of processes can rise quite a bit, ending up in a mixture of old processes trying to stop and new ones trying to do some work.


  • Allow the use of all the scoreboard slots up to ServerLimit. MaxRequestWorkers and ThreadsPerChild are used to limit the amount of active processes, meanwhile ServerLimit takes also into account the ones doing a graceful close to allow extra slots when needed. The idea is to use ServerLimit to instruct httpd about how many overall processes are tolerated before impacting the system resources.
  • Force gracefully finishing processes to close their connections in keep-alive state.
  • During graceful shutdown, if there are more running worker threads than open connections for a given process, terminate these threads to free resources faster (which may be needed for new processes).
  • If the scoreboard is full, prevent more processes to finish gracefully due to reduced load until old processes have terminated (otherwise the situation would get worse once the load increases again).





Background material


  • epoll (Linux)
  • kqueue (BSD)
  • event ports (Solaris)






  • To use this MPM on FreeBSD, FreeBSD 5.3 or higher is recommended. However, it is possible to run this MPM on FreeBSD 5.2.1, if you use libkse (see man libmap.conf).
  • For NetBSD, at least version 2.0 is recommended.
  • For Linux, a 2.6 kernel is recommended. It is also necessary to ensure that your version of glibc has been compiled with support for EPoll.

AsyncRequestWorkerFactor Directive

Description: Limit concurrent connections per process
AsyncRequestWorkerFactor factor
Default: 2
Context: server config
Status: MPM
Module: event
Compatibility: Available in version 2.3.13 and later


To mitigate this problem, the event MPM does two things:

  • it limits the number of connections accepted per process, depending on the number of idle request workers;
  • if all workers are busy, it will close connections in keep-alive state even if the keep-alive timeout has not expired. This allows the respective clients to reconnect to a different process which may still have worker threads available.


ThreadsPerChild + (AsyncRequestWorkerFactor * number of idle workers)




ThreadsPerChild = 10
ServerLimit = 4
AsyncRequestWorkerFactor = 2
MaxRequestWorkers = 40




(AsyncRequestWorkerFactor + 1) * MaxRequestWorkers


ThreadsPerChild = 10
ServerLimit = 4
MaxRequestWorkers = 40
AsyncRequestWorkerFactor = 2

If all the processes have all threads idle then:

idle_workers = 10



max_connections = (AsyncRequestWorkerFactor + 1) * MaxRequestWorkers
                = (2 + 1) * 40 = 120




© 2018 The Apache Software Foundation
Licensed under the Apache License, Version 2.0.