From: Luca Toscano Run-time configuration directives are identical to those provided by Run-time configuration directives are identical to those provided by Relationship with the Worker MPM
-event is based on the worker MPM, which implements a hybrid
+event is based on the worker MPM, which implements a hybrid
multi-process multi-threaded server. A single control process (the parent) is responsible for launching
child processes. Each child process creates a fixed number of server
threads as specified in the ThreadsPerChild directive, as well
as a listener thread which listens for connections and passes them to a worker thread for processing when they arrive.worker, with the only addition
+worker, with the only addition
of the AsyncRequestWorkerFactor.AsyncRequestWorkerFactor.
This original goal of this MPM was to fix the 'keep alive problem' in HTTP. After a client
completes the first request, it can keep the connection
- open, sending further requests using the same socket and saving
+ open, sending further requests using the same socket and saving
significant overhead in creating TCP connections. However,
- Apache HTTP Server traditionally keeps an entire child
- process/thread waiting for data from the client, which brings its own disadvantages.
+ Apache HTTP Server traditionally keeps an entire child
+ process/thread waiting for data from the client, which brings its own disadvantages.
To solve this problem, this MPM uses a dedicated listener thread for each process
along with a pool of worker threads, sharing queues specific for those
requests in keep-alive mode (or, more simply, "readable"), those in write-
@@ -108,7 +108,12 @@ of the AsyncRequestWorkerFactor.
The total amount of connections that a single process/threads block can handle is regulated +
This new architecture, leveraging non blocking sockets and modern kernel
+ features exposed by APR (like Linux's epoll),
+ does not require anymore the mpm_accept Mutex
+ configured to avoid the thundering herd problem.
The total amount of connections that a single process/threads block can handle is regulated
by the AsyncRequestWorkerFactor directive.
AsyncRequestWorkerFactor.
KeepAliveTimeout occurs then the socket will be
+ 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.AsyncRequestWorkerFactor.
These improvements are valid for both HTTP/HTTPS connections.
+These improvements are valid for both HTTP/HTTPS connections.
@@ -145,21 +150,21 @@ of theAsyncRequestWorkerFactor.
All modules shipped with the server are compatible with the event MPM.
A similar restriction is currently present for requests involving an
- output filter that needs to read and/or modify the whole response body.
+ output filter that needs to read and/or modify the whole response body.
If the connection to the client blocks while the filter is processing the
data, and the amount of data produced by the filter is too big to be
buffered in memory, the thread used for the request is not freed while
- httpd waits until the pending data is sent to the client.
- To illustrate this point we can think about the following two situations:
+ httpd waits until the pending data is sent to the client.
+ To illustrate this point we can think about the following two situations:
serving a static asset (like a CSS file) versus serving content retrieved from
- FCGI/CGI or a proxied server. The former is predictable, namely the event MPM
- has full visibility on the end of the content and it can use events: the worker
+ FCGI/CGI or a proxied server. The former is predictable, namely the event MPM
+ has full visibility on the end of the content and it can use events: the worker
thread serving the response content can flush the first bytes until EWOULDBLOCK
or EAGAIN is returned, delegating the rest to the listener. This one in turn
waits for an event on the socket, and delegates the work to flush the rest of the content
to the first idle worker thread. Meanwhile in the latter example (FCGI/CGI/proxied content)
the MPM can't predict the end of the response and a worker thread has to finish its work
- before returning the control to the listener. The only alternative is to buffer the
+ before returning the control to the listener. The only alternative is to buffer the
response in memory, but it wouldn't be the safest option for the sake of the
server's stability and memory footprint.
AsyncRequestWorkerFactor.
Before these new APIs where made available, the traditional select and poll APIs had to be used.
- Those APIs get slow if used to handle many connections or if the set of connections rate of change is high.
+
Before these new APIs where made available, the traditional select and poll APIs had to be used.
+ Those APIs get slow if used to handle many connections or if the set of connections rate of change is high.
The new APIs allow to monitor much more connections and they perform way better when the set of connections to monitor changes frequently. So these APIs made it possible to write the event MPM, that scales much better with the typical HTTP pattern of many idle connections.
The MPM assumes that the underlying apr_pollset
@@ -263,7 +268,7 @@ of the AsyncRequestWorkerFactor.
(ThreadsPerChild +
(AsyncRequestWorkerFactor *
- number of idle workers)) *
+ number of idle workers)) *
ServerLimit
When all the worker threads are idle, then absolute maximum numbers of concurrent +
When all the worker threads are idle, then absolute maximum numbers of concurrent connections can be calculared in a simpler way:
@@ -290,7 +295,7 @@ max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers))
We can calculate the absolute maximum numbers of concurrent connections in two ways:Example
- ThreadsPerChild = 10
+
ThreadsPerChild = 10
ServerLimit = 4
MaxRequestWorkers = 40
AsyncRequestWorkerFactor = 2
@@ -302,11 +307,11 @@ AsyncRequestWorkerFactor = 2max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers)) * ServerLimit
+
+
max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers)) * ServerLimit
= (10 + (2 * 10)) * 4 = 120
-
-max_connections = (AsyncRequestWorkerFactor + 1) * MaxRequestWorkers
+
+max_connections = (AsyncRequestWorkerFactor + 1) * MaxRequestWorkers
= (2 + 1) * 40 = 120