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 module is not functional. Development of this module is not
33 complete and is not currently active. Do not use
34 <module>perchild</module> unless you are a programmer willing to
38 <p>This Multi-Processing Module (MPM) implements a hybrid
39 multi-process, multi-threaded web server. A fixed number of
40 processes create threads to handle requests. Fluctuations in
41 load are handled by increasing or decreasing the number of
42 threads in each process.</p>
44 <seealso><a href="../bind.html">Setting which addresses and ports Apache
47 <section id="how-it-works"><title>How it works</title>
48 <p>A single control process launches the number of child processes
49 indicated by the <directive module="perchild">NumServers</directive>
50 directive at server startup. Each child process creates threads as
51 specified in the <directive module="mpm_common">StartThreads</directive> directive.
52 The individual threads then
53 listen for connections and serve them when they arrive.</p>
55 <p>Apache always tries to maintain a pool of <dfn>spare</dfn> or
56 idle server threads, which stand ready to serve incoming
57 requests. In this way, clients do not need to wait for new
58 threads to be created. For each child process, Apache assesses
59 the number of idle threads and creates or destroys threads to
60 keep this number within the boundaries specified by
61 <directive module="mpm_common">MinSpareThreads</directive>
62 and <directive module="mpm_common">MaxSpareThreads</directive>.
63 Since this process is very self-regulating, it is rarely
64 necessary to modify these directives from their default values.
65 The maximum number of clients that may be served simultaneously
66 is determined by multiplying the number of server processes
67 that will be created (<directive
68 module="perchild">NumServers</directive>) by the maximum
69 number of threads created in each process
70 (<directive module="mpm_common">MaxThreadsPerChild</directive>).</p>
72 <p>While the parent process is usually started as root under
73 Unix in order to bind to port 80, the child processes and
74 threads are launched by Apache as a less-privileged user. The
75 <directive module="mpm_common">User</directive> and <directive
76 module="mpm_common">Group</directive> directives are used to
77 set the privileges of the Apache child processes. The child
78 processes must be able to read all the content that will be
79 served, but should have as few privileges beyond that as
80 possible. In addition, unless <a
81 href="../suexec.html">suexec</a> is used, these directives also
82 set the privileges which will be inherited by CGI scripts.</p>
84 <p><directive module="mpm_common">MaxRequestsPerChild</directive>
85 controls how frequently the
86 server recycles processes by killing old ones and launching new
89 <section id="user-ids"><title>Working with different user-IDs</title>
90 <p>The <module>perchild</module> MPM adds the extra ability to
91 specify that particular processes should serve requests under
92 different user-IDs. These user-IDs can then be associated with
93 specific virtual hosts. You have to use one <directive
94 module="perchild">ChildPerUserID</directive> directive for
95 every user/group combination you want to be run. Then you can tie
96 particular virtual hosts to that user and group IDs.</p>
98 <p>The following example runs 7 child processes. Two of them are run
99 under <code>user1</code>/<code>group1</code>. The next four are run
100 under <code>user2</code>/<code>group2</code> and the remaining
101 process uses the <directive module="mpm_common"
102 >User</directive> and <directive module="mpm_common">Group</directive>
103 of the main server:</p>
105 <example><title>Global config</title>
107 ChildPerUserID user1 group1 2<br />
108 ChildPerUserID user2 group2 4
111 <p>Using unbalanced numbers of processes as above is useful, if the
112 particular virtual hosts produce different load. The assignment to
113 the virtual hosts is easily done as in the example below. In
114 conclusion with the example above the following assumes, that
115 <code>server2</code> has to serve about twice of the hits of
116 <code>server1</code>.</p>
118 <example><title>Example</title>
119 NameVirtualHost *<br />
121 <VirtualHost *><br />
123 ServerName fallbackhost<br />
124 # no assignment; use fallback<br />
126 </VirtualHost><br />
128 <VirtualHost *><br />
130 ServerName server1<br />
131 AssignUserID user1 group1<br />
133 </VirtualHost><br />
135 <VirtualHost *><br />
137 ServerName server2<br />
138 AssignUserID user2 group2<br />
145 <directivesynopsis location="mpm_common"><name>AcceptMutex</name>
147 <directivesynopsis location="mpm_common"><name>CoreDumpDirectory</name>
149 <directivesynopsis location="mpm_common"><name>EnableExceptionHook</name>
151 <directivesynopsis location="mpm_common"><name>Group</name>
153 <directivesynopsis location="mpm_common"><name>PidFile</name>
155 <directivesynopsis location="mpm_common"><name>Listen</name>
157 <directivesynopsis location="mpm_common"><name>ListenBacklog</name>
159 <directivesynopsis location="mpm_common"><name>LockFile</name>
161 <directivesynopsis location="mpm_common"><name>MaxRequestsPerChild</name>
163 <directivesynopsis location="mpm_common"><name>MaxSpareThreads</name>
165 <directivesynopsis location="mpm_common"><name>MinSpareThreads</name>
167 <directivesynopsis location="mpm_common"><name>ScoreBoardFile</name>
169 <directivesynopsis location="mpm_common"><name>SendBufferSize</name>
171 <directivesynopsis location="mpm_common"><name>ServerLimit</name>
173 <directivesynopsis location="mpm_common"><name>StartThreads</name>
175 <directivesynopsis location="mpm_common"><name>ThreadLimit</name>
177 <directivesynopsis location="mpm_common"><name>ThreadStackSize</name>
179 <directivesynopsis location="mpm_common"><name>User</name>
183 <name>AssignUserID</name>
184 <description>Tie a virtual host to a user and group ID</description>
185 <syntax>AssignUserID <var>user-id</var> <var>group-id</var></syntax>
186 <contextlist><context>virtual host</context></contextlist>
189 <p>Tie a virtual host to a specific user/group combination. Requests
190 addressed to the virtual host where this directive appears will be
191 served by a process running with the specified user and group ID.</p>
193 <p>The user and group ID has to be assigned to a number of children
194 in the global server config using the <directive module="perchild"
195 >ChildPerUserID</directive> directive. See the section above for a
196 <a href="#user-ids">configuration example</a>.</p>
201 <name>ChildPerUserID</name>
202 <description>Specify user ID and group ID for a number of child
203 processes</description>
204 <syntax>ChildPerUserID <var>user-id</var> <var>group-id</var>
205 <var>num-children</var></syntax>
206 <contextlist><context>server config</context></contextlist>
209 <p>Specify a user ID and group ID for a number of child processes.
210 The third argument, <var>num-children</var>, is the number of child
211 processes to start with the specified user and group. It does
212 <em>not</em> represent a specific child number. In order to use this
213 directive, the server must be run initially as <code>root</code>.
214 If you start the server as a non-root user, it will fail to change
215 to the lesser privileged user.</p>
217 <p>If the total number of child processes, found by totaling all of the
218 third arguments to all <directive>ChildPerUserID</directive> directives
219 in the config file, is less than <directive module="perchild"
220 >NumServers</directive>, then all remaining children will inherit the
221 <directive module="mpm_common">User</directive> and <directive
222 module="mpm_common">Group</directive> settings from the main server.
223 See the section above for a <a href="#user-ids">configuration
226 <note type="warning"><title>Security</title>
227 <p>Don't set <var>user-id</var> (or <var>group-id</var>) to
228 <code>root</code> unless you know exactly what you are doing, and
229 what the dangers are.</p>
235 <name>MaxThreadsPerChild</name>
236 <description>Maximum number of threads per child process</description>
237 <syntax>MaxThreadsPerChild <var>number</var></syntax>
238 <default>MaxThreadsPerChild 64</default>
239 <contextlist><context>server config</context></contextlist>
242 <p>This directive sets the maximum number of threads that will be
243 created in each child process. To increase this value beyond its
244 default, it is necessary to change the value of the <directive
245 module="mpm_common">ThreadLimit</directive> directive and stop and
246 re-start the server.</p>
251 <name>NumServers</name>
252 <description>Total number of children alive at the same time</description>
253 <syntax>NumServers <var>number</var></syntax>
254 <default>NumServers 2</default>
255 <contextlist><context>server config</context></contextlist>
258 <p>The <directive>NumServers</directive> directive determines the number
259 of children alive at the same time. This number should be large enough to
260 handle the requests for the entire site. To increase this value beyond the
261 value of <code>8</code>, it is necessary to change the value of the
262 <directive module="mpm_common">ServerLimit</directive> directive and stop
263 and re-start the server. See the section above for a <a href="#user-ids"
264 >configuration example</a>.</p>