From 167c4c00c34cc80d0d54fa8a0ed6dd6b807d0c54 Mon Sep 17 00:00:00 2001 From: Luca Toscano Date: Fri, 29 Apr 2016 12:40:49 +0000 Subject: Added a specific reference to mpm-event's doc about the fact that mpm-accept is not needed anymore git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1741621 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/event.xml | 69 +++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'docs/manual') diff --git a/docs/manual/mod/event.xml b/docs/manual/mod/event.xml index 9d2722a3e5..efad7a146c 100644 --- a/docs/manual/mod/event.xml +++ b/docs/manual/mod/event.xml @@ -44,13 +44,13 @@ of consuming threads only for connections with active processing The worker MPM
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.

-

Run-time configuration directives are identical to those provided by worker, with the only addition +

Run-time configuration directives are identical to those provided by worker, with the only addition of the AsyncRequestWorkerFactor.

@@ -58,10 +58,10 @@ of the AsyncRequestWorkerFactor.

How it Works

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- @@ -70,7 +70,12 @@ of the AsyncRequestWorkerFactor.

adjusts these queues and pushes work to the worker pool.

-

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.

Async connections @@ -85,9 +90,9 @@ of the AsyncRequestWorkerFactor.

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 + 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.
@@ -95,7 +100,7 @@ of the AsyncRequestWorkerFactor.

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. So in such cases, httpd tries to read the rest of the request to allow the client to consume the response. The lingering close is time bounded but it can take relatively long time, so a worker thread can offload this work to the listener.
-

These improvements are valid for both HTTP/HTTPS connections.

+

These improvements are valid for both HTTP/HTTPS connections.

@@ -107,21 +112,21 @@ of the AsyncRequestWorkerFactor.

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.

@@ -135,8 +140,8 @@ of the AsyncRequestWorkerFactor.

  • kqueue (BSD)
  • event ports (Solaris)
  • -

    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

    @@ -277,13 +282,13 @@ MaxRequestWorkers = 40 idle_workers = 4 (average for all the processes to keep it simple) -max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers)) * ServerLimit +max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers)) * ServerLimit = (10 + (2 * 4)) * 4 = 72 - + -

    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:

    @@ -294,12 +299,12 @@ max_connections = (ThreadsPerChild + (AsyncRequestWorkerFactor * idle_workers)) Example - -ThreadsPerChild = 10 + +ThreadsPerChild = 10 ServerLimit = 4 MaxRequestWorkers = 40 -AsyncRequestWorkerFactor = 2 - +AsyncRequestWorkerFactor = 2 +

    If all the processes have all threads idle then:

    @@ -307,15 +312,15 @@ AsyncRequestWorkerFactor = 2 idle_workers = 10

    We can calculate the absolute maximum numbers of concurrent connections in two ways:

    - + - -max_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 - + -- cgit v1.2.3