2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
6 Copyright 2002-2004 The Apache Software Foundation
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
21 <modulesynopsis metafile="perchild.xml.meta">
24 <description>Multi-Processing Module allowing for daemon processes serving
25 requests to be assigned a variety of different userids</description>
27 <sourcefile>perchild.c</sourcefile>
28 <identifier>mpm_perchild_module</identifier>
32 This MPM does not currently work on most platforms. Work is ongoing
33 to make it functional.
36 <p>This Multi-Processing Module (MPM) implements a hybrid
37 multi-process, multi-threaded web server. A fixed number of
38 processes create threads to handle requests. Fluctuations in
39 load are handled by increasing or decreasing the number of
40 threads in each process.</p>
42 <seealso><a href="../bind.html">Setting which addresses and ports Apache
45 <section id="how-it-works"><title>How it works</title>
46 <p>A single control process launches the number of child processes
47 indicated by the <directive module="perchild">NumServers</directive>
48 directive at server startup. Each child process creates threads as
49 specified in the <directive module="mpm_common">StartThreads</directive> directive.
50 The individual threads then
51 listen for connections and serve them when they arrive.</p>
53 <p>Apache always tries to maintain a pool of <dfn>spare</dfn> or
54 idle server threads, which stand ready to serve incoming
55 requests. In this way, clients do not need to wait for new
56 threads to be created. For each child process, Apache assesses
57 the number of idle threads and creates or destroys threads to
58 keep this number within the boundaries specified by
59 <directive module="mpm_common">MinSpareThreads</directive>
60 and <directive module="mpm_common">MaxSpareThreads</directive>.
61 Since this process is very self-regulating, it is rarely
62 necessary to modify these directives from their default values.
63 The maximum number of clients that may be served simultaneously
64 is determined by multiplying the number of server processes
65 that will be created (<directive
66 module="perchild">NumServers</directive>) by the maximum
67 number of threads created in each process
68 (<directive module="mpm_common">MaxThreadsPerChild</directive>).</p>
70 <p>While the parent process is usually started as root under
71 Unix in order to bind to port 80, the child processes and
72 threads are launched by Apache as a less-privileged user. The
73 <directive module="mpm_common">User</directive> and <directive
74 module="mpm_common">Group</directive> directives are used to
75 set the privileges of the Apache child processes. The child
76 processes must be able to read all the content that will be
77 served, but should have as few privileges beyond that as
78 possible. In addition, unless <a
79 href="../suexec.html">suexec</a> is used, these directives also
80 set the privileges which will be inherited by CGI scripts.</p>
82 <p><directive module="mpm_common">MaxRequestsPerChild</directive>
83 controls how frequently the
84 server recycles processes by killing old ones and launching new
87 <section id="user-ids"><title>Working with different user-IDs</title>
88 <p>The <module>perchild</module> MPM adds the extra ability to
89 specify that particular processes should serve requests under
90 different user-IDs. These user-IDs can then be associated with
91 specific virtual hosts. You have to use one <directive
92 module="perchild">ChildPerUserID</directive> directive for
93 every user/group combination you want to be run. Then you can tie
94 particular virtual hosts to that user and group IDs.</p>
96 <p>The following example runs 7 child processes. Two of them are run
97 under <code>user1</code>/<code>group1</code>. The next four are run
98 under <code>user2</code>/<code>group2</code> and the remaining
99 process uses the <directive module="mpm_common"
100 >User</directive> and <directive module="mpm_common">Group</directive>
101 of the main server:</p>
103 <example><title>Global config</title>
105 ChildPerUserID user1 group1 2<br />
106 ChildPerUserID user2 group2 4
109 <p>Using unbalanced numbers of processes as above is useful, if the
110 particular virtual hosts produce different load. The assignment to
111 the virtual hosts is easily done as in the example below. In
112 conclusion with the example above the following assumes, that
113 <code>server2</code> has to serve about twice of the hits of
114 <code>server1</code>.</p>
116 <example><title>Example</title>
117 NameVirtualHost *<br />
119 <VirtualHost *><br />
121 ServerName fallbackhost<br />
122 # no assignment; use fallback<br />
124 </VirtualHost><br />
126 <VirtualHost *><br />
128 ServerName server1<br />
129 AssignUserID user1 group1<br />
131 </VirtualHost><br />
133 <VirtualHost *><br />
135 ServerName server2<br />
136 AssignUserID user2 group2<br />
143 <directivesynopsis location="mpm_common"><name>AcceptMutex</name>
145 <directivesynopsis location="mpm_common"><name>CoreDumpDirectory</name>
147 <directivesynopsis location="mpm_common"><name>Group</name>
149 <directivesynopsis location="mpm_common"><name>PidFile</name>
151 <directivesynopsis location="mpm_common"><name>Listen</name>
153 <directivesynopsis location="mpm_common"><name>ListenBacklog</name>
155 <directivesynopsis location="mpm_common"><name>LockFile</name>
157 <directivesynopsis location="mpm_common"><name>MaxRequestsPerChild</name>
159 <directivesynopsis location="mpm_common"><name>MaxSpareThreads</name>
161 <directivesynopsis location="mpm_common"><name>MinSpareThreads</name>
163 <directivesynopsis location="mpm_common"><name>ScoreBoardFile</name>
165 <directivesynopsis location="mpm_common"><name>SendBufferSize</name>
167 <directivesynopsis location="mpm_common"><name>ServerLimit</name>
169 <directivesynopsis location="mpm_common"><name>StartThreads</name>
171 <directivesynopsis location="mpm_common"><name>ThreadLimit</name>
173 <directivesynopsis location="mpm_common"><name>User</name>
177 <name>AssignUserID</name>
178 <description>Tie a virtual host to a user and group ID</description>
179 <syntax>AssignUserID <var>user-id</var> <var>group-id</var></syntax>
180 <contextlist><context>virtual host</context></contextlist>
183 <p>Tie a virtual host to a specific user/group combination. Requests
184 addressed to the virtual host where this directive appears will be
185 served by a process running with the specified user and group ID.</p>
187 <p>The user and group ID has to be assigned to a number of children
188 in the global server config using the <directive module="perchild"
189 >ChildPerUserID</directive> directive. See the section above for a
190 <a href="#user-ids">configuration example</a>.</p>
195 <name>ChildPerUserID</name>
196 <description>Specify user ID and group ID for a number of child
197 processes</description>
198 <syntax>ChildPerUserID <var>user-id</var> <var>group-id</var>
199 <var>num-children</var></syntax>
200 <contextlist><context>server config</context></contextlist>
203 <p>Specify a user ID and group ID for a number of child processes.
204 The third argument, <var>num-children</var>, is the number of child
205 processes to start with the specified user and group. It does
206 <em>not</em> represent a specific child number. In order to use this
207 directive, the server must be run initially as <code>root</code>.
208 If you start the server as a non-root user, it will fail to change
209 to the lesser privileged user.</p>
211 <p>If the total number of child processes, found by totaling all of the
212 third arguments to all <directive>ChildPerUserID</directive> directives
213 in the config file, is less than <directive module="perchild"
214 >NumServers</directive>, then all remaining children will inherit the
215 <directive module="mpm_common">User</directive> and <directive
216 module="mpm_common">Group</directive> settings from the main server.
217 See the section above for a <a href="#user-ids">configuration
220 <note type="warning"><title>Security</title>
221 <p>Don't set <var>user-id</var> (or <var>group-id</var>) to
222 <code>root</code> unless you know exactly what you are doing, and
223 what the dangers are.</p>
229 <name>MaxThreadsPerChild</name>
230 <description>Maximum number of threads per child process</description>
231 <syntax>MaxThreadsPerChild <var>number</var></syntax>
232 <default>MaxThreadsPerChild 64</default>
233 <contextlist><context>server config</context></contextlist>
236 <p>This directive sets the maximum number of threads that will be
237 created in each child process. To increase this value beyond its
238 default, it is necessary to change the value of the <directive
239 module="mpm_common">ThreadLimit</directive> directive and stop and
240 re-start the server.</p>
245 <name>NumServers</name>
246 <description>Total number of children alive at the same time</description>
247 <syntax>NumServers <var>number</var></syntax>
248 <default>NumServers 2</default>
249 <contextlist><context>server config</context></contextlist>
252 <p>The <directive>NumServers</directive> directive determines the number
253 of children alive at the same time. This number should be large enough to
254 handle the requests for the entire site. To increase this value beyond the
255 value of <code>8</code>, it is necessary to change the value of the
256 <directive module="mpm_common">ServerLimit</directive> directive and stop
257 and re-start the server. See the section above for a <a href="#user-ids"
258 >configuration example</a>.</p>