883N/A<
description>Multi-Processing Module implementing a hybrid
883N/A multi-threaded multi-process web server</
description>
883N/A<
identifier>mpm_worker_module</
identifier>
883N/A <
p>This Multi-Processing Module (MPM) implements a hybrid
883N/A multi-process multi-threaded server. By using threads to serve
883N/A requests, it is able to serve a large number of requests with
883N/A less system resources than a process-based server. Yet it
883N/A retains much of the stability of a process-based server by
883N/A keeping multiple processes available, each with many threads.</
p>
883N/A <
p>The most important directives used to control this MPM are
883N/A <
directive module="mpm_common">ThreadsPerChild</
directive>, which
883N/A controls the number of threads deployed by each child process and
883N/A <
directive module="mpm_common">MaxClients</
directive>, which
883N/A controls the maximum total number of threads that may be
883N/A<
seealso><
a href="/bind.html">Setting which addresses and ports Apache
<
section id="how-it-works"><
title>How it Works</
title>
<
p>Each process has a fixed
number of threads. The server adjusts to handle load by
increasing or decreasing the number of processes.</
p>
<
p>A single control process is responsible for launching child
processes. Each child process creates a fixed number of threads as
specified in the <
directive module="mpm_common">ThreadsPerChild</
directive> directive. The
individual threads then listen for connections and serve them when
<
p>Apache always tries to maintain a pool of <
dfn>spare</
dfn> or
idle server threads, which stand ready to serve incoming
requests. In this way, clients do not need to wait for a new
threads or processes to be created before their requests can be
served. The number of processes that will initially launched is
set by the <
directive module="mpm_common">StartServers</
directive>
directive. Then during operation, Apache assesses the total number
of idle threads in all processes, and forks or kills processes to
keep this number within the boundaries specified by <
directive module="mpm_common">MinSpareThreads</
directive> and <
directive module="mpm_common">MaxSpareThreads</
directive>. Since this
process is very self-regulating, it is rarely necessary to modify
these directives from their default values. The maximum number of
clients that may be served simultaneously (
i.e., the maximum total
number of threads in all processes) is determined by the
<
directive module="mpm_common">MaxClients</
directive> directive,
while the maximum number of processes that can be launched is set
by the <
directive module="mpm_common">ServerLimit</
directive>
directive. <
directive module="mpm_common">ServerLimit</
directive>
module="mpm_common">ThreadsPerChild</
directive> must be greater
than or equal to <
directive module="mpm_common">MaxClients</
directive></
p>
<
p>A typical configuration of the process-thread controls in
the <
module>worker</
module> MPM could look as follows:</
p>
<
p>While the parent process is usually started as <
code>root</
code>
under Unix in order to bind to port 80, the child processes and threads
are launched by Apache as a less-privileged user. The <
directive module="mpm_common">User</
directive> and <
directive module="mpm_common">Group</
directive> directives are used to set
the privileges of the Apache child processes. The child processes
must be able to read all the content that will be served, but
should have as few privileges beyond that as possible. In
addition, unless <
a href="/suexec.html">suexec</
a> is used,
these directives also set the privileges which will be inherited
<
p><
directive module="mpm_common">MaxRequestsPerChild</
directive>
controls how frequently the server recycles processes by killing
old ones and launching new ones.</
p>
<
directivesynopsis location="mpm_common"><
name>AcceptMutex</
name>
<
directivesynopsis location="mpm_common"><
name>CoreDumpDirectory</
name>
<
directivesynopsis location="mpm_common"><
name>Group</
name>
<
directivesynopsis location="mpm_common"><
name>PidFile</
name>
<
directivesynopsis location="mpm_common"><
name>Listen</
name>
<
directivesynopsis location="mpm_common"><
name>ListenBacklog</
name>
<
directivesynopsis location="mpm_common"><
name>LockFile</
name>
<
directivesynopsis location="mpm_common"><
name>MaxClients</
name>
<
directivesynopsis location="mpm_common"><
name>MaxMemFree</
name>
<
directivesynopsis location="mpm_common"><
name>MaxRequestsPerChild</
name>
<
directivesynopsis location="mpm_common"><
name>MaxSpareThreads</
name>
<
directivesynopsis location="mpm_common"><
name>MinSpareThreads</
name>
<
directivesynopsis location="mpm_common"><
name>ScoreBoardFile</
name>
<
directivesynopsis location="mpm_common"><
name>SendBufferSize</
name>
<
directivesynopsis location="mpm_common"><
name>ServerLimit</
name>
<
directivesynopsis location="mpm_common"><
name>StartServers</
name>
<
directivesynopsis location="mpm_common"><
name>ThreadLimit</
name>
<
directivesynopsis location="mpm_common"><
name>ThreadsPerChild</
name>
<
directivesynopsis location="mpm_common"><
name>User</
name>