2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="event.xml.meta">
25 <description>A variant of the <module>worker</module> MPM with the goal
26 of consuming threads only for connections with active processing</description>
28 <sourcefile>event.c</sourcefile>
29 <identifier>mpm_event_module</identifier>
32 <p>The <module>event</module> Multi-Processing Module (MPM) is
33 designed to allow more requests to be served simultaneously by
34 passing off some processing work to supporting threads, freeing up
35 the main threads to work on new requests. It is based on the
36 <module>worker</module> MPM, which implements a hybrid
37 multi-process multi-threaded server. Run-time configuration
38 directives are identical to those provided by
39 <module>worker</module>.</p>
41 <p>To use the <module>event</module> MPM, add
42 <code>--with-mpm=event</code> to the <program>configure</program>
43 script's arguments when building the <program>httpd</program>.</p>
47 <seealso><a href="worker.html">The worker MPM</a></seealso>
49 <section id="how-it-works"><title>How it Works</title>
50 <p>This MPM tries to fix the 'keep alive problem' in HTTP. After a client
51 completes the first request, the client can keep the connection
52 open, and send further requests using the same socket. This can
53 save significant overhead in creating TCP connections. However,
54 Apache HTTP Server traditionally keeps an entire child process/thread waiting
55 for data from the client, which brings its own disadvantages. To
56 solve this problem, this MPM uses a dedicated thread to handle both
57 the Listening sockets, all sockets that are in a Keep Alive state,
58 and sockets where the handler and protocol filters have done their work
59 and the only remaining thing to do is send the data to the client. The
60 status page of <module>mod_status</module> shows how many connections are
61 in the mentioned states.</p>
63 <p>The improved connection handling may not work for certain connection
64 filters that have declared themselves as incompatible with event. In these
65 cases, this MPM will fall back to the behaviour of the
66 <module>worker</module> MPM and reserve one worker thread per connection.
67 All modules shipped with the server are compatible with the event MPM.</p>
69 <p>A similar restriction is currently present for requests involving an
70 output filter that needs to read and/or modify the whole response body,
71 like for example mod_ssl, mod_deflate, or mod_include. If the
72 connection to the client blocks while the filter is processing the
73 data, and the amount of data produced by the filter is too big to be
74 buffered in memory, the thread used for the request is not freed while
75 httpd waits until the pending data is sent to the client.</p>
77 <p>The MPM assumes that the underlying <code>apr_pollset</code>
78 implementation is reasonably threadsafe. This enables the MPM to
79 avoid excessive high level locking, or having to wake up the listener
80 thread in order to send it a keep-alive socket. This is currently
81 only compatible with KQueue and EPoll.</p>
84 <section id="requirements"><title>Requirements</title>
85 <p>This MPM depends on <glossary>APR</glossary>'s atomic
86 compare-and-swap operations for thread synchronization. If you are
87 compiling for an x86 target and you don't need to support 386s, or
88 you are compiling for a SPARC and you don't need to run on
89 pre-UltraSPARC chips, add
90 <code>--enable-nonportable-atomics=yes</code> to the
91 <program>configure</program> script's arguments. This will cause
92 APR to implement atomic operations using efficient opcodes not
93 available in older CPUs.</p>
95 <p>This MPM does not perform well on older platforms which lack good
96 threading, but the requirement for EPoll or KQueue makes this
101 <li>To use this MPM on FreeBSD, FreeBSD 5.3 or higher is recommended.
102 However, it is possible to run this MPM on FreeBSD 5.2.1, if you
103 use <code>libkse</code> (see <code>man libmap.conf</code>).</li>
105 <li>For NetBSD, at least version 2.0 is recommended.</li>
107 <li>For Linux, a 2.6 kernel is recommended. It is also necessary to
108 ensure that your version of <code>glibc</code> has been compiled
109 with support for EPoll.</li>
114 <directivesynopsis location="mpm_common"><name>CoreDumpDirectory</name>
116 <directivesynopsis location="mpm_common"><name>EnableExceptionHook</name>
118 <directivesynopsis location="mod_unixd"><name>Group</name>
120 <directivesynopsis location="mpm_common"><name>Listen</name>
122 <directivesynopsis location="mpm_common"><name>ListenBacklog</name>
124 <directivesynopsis location="mpm_common"><name>SendBufferSize</name>
126 <directivesynopsis location="mpm_common"><name>MaxRequestWorkers</name>
128 <directivesynopsis location="mpm_common"><name>MaxMemFree</name>
130 <directivesynopsis location="mpm_common"><name>MaxConnectionsPerChild</name>
132 <directivesynopsis location="mpm_common"><name>MaxSpareThreads</name>
134 <directivesynopsis location="mpm_common"><name>MinSpareThreads</name>
136 <directivesynopsis location="mpm_common"><name>PidFile</name>
138 <directivesynopsis location="mpm_common"><name>ScoreBoardFile</name>
140 <directivesynopsis location="mpm_common"><name>ServerLimit</name>
142 <directivesynopsis location="mpm_common"><name>StartServers</name>
144 <directivesynopsis location="mpm_common"><name>ThreadLimit</name>
146 <directivesynopsis location="mpm_common"><name>ThreadsPerChild</name>
148 <directivesynopsis location="mpm_common"><name>ThreadStackSize</name>
150 <directivesynopsis location="mod_unixd"><name>User</name>
154 <name>AsyncRequestWorkerFactor</name>
155 <description>Limit concurrent connections per process</description>
156 <syntax>AsyncRequestWorkerFactor <var>factor</var></syntax>
158 <contextlist><context>server config</context> </contextlist>
159 <compatibility>Available in version 2.3.13 and later</compatibility>
162 <p>The event MPM handles some connections in an asynchronous way, where
163 request worker threads are only allocated for short periods of time as
164 needed, and other connections with one request worker thread reserved per
165 connection. This can lead to situations where all workers are tied up and
166 no worker thread is available to handle new work on established async
169 <p>To mitigate this problem, the event MPM does two things: Firstly, it
170 limits the number of connections accepted per process, depending on the
171 number of idle request workers. Secondly, if all workers are busy, it will
172 close connections in keep-alive state even if the keep-alive timeout has
173 not expired. This allows the respective clients to reconnect to a
174 different process which may still have worker threads available.</p>
176 <p>This directive can be used to fine-tune the per-process connection
177 limit. A process will only accept new connections if the current number of
178 connections (not counting connections in the "closing" state) is lower
181 <p class="indent"><strong>
182 <directive module="mpm_common">ThreadsPerChild</directive> +
183 (<directive>AsyncRequestWorkerFactor</directive> *
184 <var>number of idle workers</var>)
187 <p>This means the absolute maximum numbers of concurrent connections is:</p>
189 <p class="indent"><strong>
190 (<directive>AsyncRequestWorkerFactor</directive> + 1) *
191 <directive module="mpm_common">MaxRequestWorkers</directive>
194 <p><directive module="mpm_common">MaxRequestWorkers</directive> was called
195 <directive>MaxClients</directive> prior to version 2.3.13. The above value
196 shows that the old name did not accurately describe its meaning for the event MPM.</p>
198 <p><directive>AsyncRequestWorkerFactor</directive> can take non-integer
199 arguments, e.g "1.5".</p>