]> granicus.if.org Git - apache/blob - docs/manual/mod/worker.xml
XML update.
[apache] / docs / manual / mod / worker.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="worker.xml.meta">
24 <name>worker</name>
25 <description>Multi-Processing Module implementing a hybrid
26     multi-threaded multi-process web server</description>
27 <status>MPM</status>
28 <sourcefile>worker.c</sourcefile>
29 <identifier>mpm_worker_module</identifier>
30
31 <summary>
32     <p>This Multi-Processing Module (MPM) implements a hybrid
33     multi-process multi-threaded server. By using threads to serve
34     requests, it is able to serve a large number of requests with
35     fewer system resources than a process-based server. However, it
36     retains much of the stability of a process-based server by
37     keeping multiple processes available, each with many threads.</p>
38
39     <p>The most important directives used to control this MPM are
40     <directive module="mpm_common">ThreadsPerChild</directive>, which
41     controls the number of threads deployed by each child process and
42     <directive module="mpm_common">MaxRequestWorkers</directive>, which
43     controls the maximum total number of threads that may be
44     launched.</p>
45 </summary>
46 <seealso><a href="../bind.html">Setting which addresses and ports Apache HTTP Server uses</a></seealso>
47
48 <section id="how-it-works"><title>How it Works</title>
49     <p>A single control process (the parent) is responsible for launching
50     child processes. Each child process creates a fixed number of server
51     threads as specified in the <directive
52     module="mpm_common">ThreadsPerChild</directive> directive, as well
53     as a listener thread which listens for connections and passes them
54     to a server thread for processing when they arrive.</p>
55
56     <p>Apache HTTP Server always tries to maintain a pool of <dfn>spare</dfn> or
57     idle server threads, which stand ready to serve incoming
58     requests. In this way, clients do not need to wait for a new
59     threads or processes to be created before their requests can be
60     served. The number of processes that will initially launch is
61     set by the <directive module="mpm_common">StartServers</directive>
62     directive. During operation, the server assesses the total number
63     of idle threads in all processes, and forks or kills processes to
64     keep this number within the boundaries specified by <directive
65     module="mpm_common">MinSpareThreads</directive> and <directive
66     module="mpm_common">MaxSpareThreads</directive>. Since this
67     process is very self-regulating, it is rarely necessary to modify
68     these directives from their default values. The maximum number of
69     clients that may be served simultaneously (i.e., the maximum total
70     number of threads in all processes) is determined by the
71     <directive module="mpm_common">MaxRequestWorkers</directive> directive.
72     The maximum number of active child processes is determined by
73     the <directive module="mpm_common">MaxRequestWorkers</directive>
74     directive divided by the <directive module="mpm_common">
75     ThreadsPerChild</directive> directive.</p>
76
77     <p>Two directives set hard limits on the number of active child
78     processes and the number of server threads in a child process,
79     and can only be changed by fully stopping the server and then
80     starting it again.  <directive module="mpm_common">ServerLimit
81     </directive> is a hard limit on the number of active child
82     processes, and must be greater than or equal to the
83     <directive module="mpm_common">MaxRequestWorkers</directive>
84     directive divided by the <directive module="mpm_common">
85     ThreadsPerChild</directive> directive.
86     <directive module="mpm_common">ThreadLimit</directive> is a hard
87     limit of the number of server threads, and must be greater than
88     or equal to the <directive
89     module="mpm_common">ThreadsPerChild</directive> directive.</p>
90
91     <p>In addition to the set of active child processes, there may
92     be additional child processes which are terminating, but where at
93     least one server thread is still handling an existing client
94     connection.  Up to <directive
95     module="mpm_common">MaxRequestWorkers</directive> terminating processes
96     may be present, though the actual number can be expected to be
97     much smaller.  This behavior can be avoided by disabling the
98     termination of individual child processes, which is achieved using
99     the following:</p>
100
101     <ul>
102       <li>set the value of <directive module="mpm_common">
103       MaxConnectionsPerChild</directive> to zero</li>
104
105       <li>set the value of <directive module="mpm_common">
106       MaxSpareThreads</directive> to the same value as
107       <directive module="mpm_common">MaxRequestWorkers</directive></li>
108     </ul>
109
110     <p>A typical configuration of the process-thread controls in
111     the <module>worker</module> MPM could look as follows:</p>
112
113     <highlight language="config">
114 ServerLimit         16
115 StartServers         2
116 MaxRequestWorkers  150
117 MinSpareThreads     25
118 MaxSpareThreads     75
119 ThreadsPerChild     25
120     </highlight>
121
122     <p>While the parent process is usually started as <code>root</code>
123     under Unix in order to bind to port 80, the child processes and threads
124     are launched by the server as a less-privileged user. The <directive
125     module="mod_unixd">User</directive> and <directive
126     module="mod_unixd">Group</directive> directives are used to set
127     the privileges of the Apache HTTP Server child processes. The child processes
128     must be able to read all the content that will be served, but
129     should have as few privileges beyond that as possible. In
130     addition, unless <program>suexec</program> is used,
131     these directives also set the privileges which will be inherited
132     by CGI scripts.</p>
133
134     <p><directive module="mpm_common">MaxConnectionsPerChild</directive>
135     controls how frequently the server recycles processes by killing
136     old ones and launching new ones.</p>
137
138     <p>This MPM uses the <code>mpm-accept</code> mutex to serialize
139     access to incoming connections when subject to the thundering herd
140     problem (generally, when there are multiple listening sockets).
141     The implementation aspects of this mutex can be configured with the
142     <directive module="core">Mutex</directive> directive.  The <a
143     href="../misc/perf-tuning.html">performance hints</a>
144     documentation has additional information about this mutex.</p>
145 </section>
146
147 <directivesynopsis location="mpm_common"><name>CoreDumpDirectory</name>
148 </directivesynopsis>
149 <directivesynopsis location="mpm_common"><name>EnableExceptionHook</name>
150 </directivesynopsis>
151 <directivesynopsis location="mod_unixd"><name>Group</name>
152 </directivesynopsis>
153 <directivesynopsis location="mpm_common"><name>PidFile</name>
154 </directivesynopsis>
155 <directivesynopsis location="mpm_common"><name>Listen</name>
156 </directivesynopsis>
157 <directivesynopsis location="mpm_common"><name>ListenBacklog</name>
158 </directivesynopsis>
159 <directivesynopsis location="mpm_common"><name>MaxRequestWorkers</name>
160 </directivesynopsis>
161 <directivesynopsis location="mpm_common"><name>MaxMemFree</name>
162 </directivesynopsis>
163 <directivesynopsis location="mpm_common"><name>MaxConnectionsPerChild</name>
164 </directivesynopsis>
165 <directivesynopsis location="mpm_common"><name>MaxSpareThreads</name>
166 </directivesynopsis>
167 <directivesynopsis location="mpm_common"><name>MinSpareThreads</name>
168 </directivesynopsis>
169 <directivesynopsis location="mpm_common"><name>ScoreBoardFile</name>
170 </directivesynopsis>
171 <directivesynopsis location="mpm_common"><name>ReceiveBufferSize</name>
172 </directivesynopsis>
173 <directivesynopsis location="mpm_common"><name>SendBufferSize</name>
174 </directivesynopsis>
175 <directivesynopsis location="mpm_common"><name>ServerLimit</name>
176 </directivesynopsis>
177 <directivesynopsis location="mpm_common"><name>StartServers</name>
178 </directivesynopsis>
179 <directivesynopsis location="mpm_common"><name>ThreadLimit</name>
180 </directivesynopsis>
181 <directivesynopsis location="mpm_common"><name>ThreadsPerChild</name>
182 </directivesynopsis>
183 <directivesynopsis location="mpm_common"><name>ThreadStackSize</name>
184 </directivesynopsis>
185 <directivesynopsis location="mod_unixd"><name>User</name>
186 </directivesynopsis>
187
188 </modulesynopsis>