<!-- Simplified Chinese Translated: Neumann Wong <lemuel@exusiai.moe> Reviewed by: Zhun Huang <hzcdl@cn.ibm.com> -->
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
<?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<manualpage metafile="mpm.xml.meta">

  <title>多进程处理模块（MPM）</title>

<summary>
<p>本文档介绍了多进程处理模块及Apache HTTP Server如何使用该模块。</p>
</summary>

<section id="introduction"><title>简介</title>
    <p>
    Apache HTTP Server是以强大、灵活为方向设计的多平台万维网服务器。
    在不同平台、环境中通常需要不同的功能和特性，或通过不同的方式高效地
    实现某一功能。得益于Apache httpd模块化的设计思路，它可以适应多种环境。
    这种设计允许网络管理员通过在编译、运行时选择加载什么模块来决定服务器的功能。</p>

    <p>Apache HTTP Server的2.0版本将模块化设计思路拓展到了网络服务器的
    基本功能中。它提供了一系列可以用于绑定端口、接受并调度子进程处理请求的
    多进程处理模块（MPMs）。</p>

    <p>如此程度的模块化设计，可以为我们的网络服务器带来如下两个重要好处。</p>

    <ul>
      <li>Apache httpd能更妥善、高效地在多种操作系统中工作。尤其是在Windows版
      的Apache HTTP Server中，<module>mpm_winnt</module>可以通过原生网络
      功能取代先前1.3版本的POSIX层。该优势也延伸到了其他已实现对应多进程处理
      模块的操作系统中。</li>

      <li>Apache HTTP server可以更好的为特定站点的需要进行定制。例如，
      有高可扩缩性需求的站点可以使用<module>worker</module>或<module>event</module>
      这样线程化的多进程处理模块，而对于有高可靠性或兼容性需求的站点，
      则可以选择使用<module>prefork</module>。</li>
    </ul>

    <p>你可能会觉得多进程处理模块很像其他Apache httpd模块。确实如此，不过不同的是，
    在运行期间内，服务器只能载入一个多进程处理模块。如需查看全部可用的多进程处理模块，
    请见<a href="mod/">模块索引</a>。</p>

</section>

<section id="defaults"><title>默认的多进程处理模块</title>

<p>下方表单列出了不同系统默认使用的多进程处理模块，该多进程处理模块将在你未在编译时
指定启用哪个多进程处理模块的情况下默认启用。</p>

<table border="1" style="zebra">
<columnspec><column width=".2"/><column width=".2"/></columnspec>
<tr><td>Netware</td><td><module>mpm_netware</module></td></tr>
<tr><td>OS/2</td><td><module>mpmt_os2</module></td></tr>
<tr><td>Unix</td><td><module>prefork</module>, <module>worker</module>, or
    <module>event</module>, depending on platform capabilities</td></tr>
<tr><td>Windows</td><td><module>mpm_winnt</module></td></tr>
</table>

<note><p>此处的“Unix”指代包含Linux、BSD、Solaris、Mac OS X等在内的类Unix操作系统。</p></note>

<p>对于Unix而言，多进程处理模块的选择取决于两个问题：</p>
<p>1.系统是否支持线程？</p>
<p>2.系统是否支持线程安全的轮询，特别是kqueue和epoll功能？</p>

<p>如果这两个问题的答案都是“是”，那么默认的多进程处理模块就是<module>event</module>。</p>

<p>如果问题1的答案是“是”，问题2的答案是“否”，那么默认的多进程处理模块是<module>worker</module>。</p>

<p>如果两个问题的答案都是“否”，那么默认的多进程处理模块是<module>prefork</module>。</p>

<p>一般来说，现代操作系统都支持这两个功能，在现代操作系统中安装的Apache HTTP Server
的默认多进程处理模块通常是<module>event</module>。</p>

</section>

<section id="static"><title>静态构建多进程处理模块</title>

    <p>多进程处理模块可以在各平台上作为静态模块构建，并链接到服务器中。
    这样构建的服务器，如果需要修改多进程处理模块，就还需要重新构建一遍服务器。</p>

    <p>你可以使用<program>configure</program>脚本的<code>--with-mpm=<em>NAME</em></code>
    选项，指定你想使用的多进程处理模块。<em>NAME</em>是你想要的多进程处理模块的名称。</p>

    <p>服务器编译完成后，可以使用<code>./httpd -l</code>来确定所选的多进程处理模块。
    该命令会列出包括多进程处理模块在内的，编译入服务器内的全部模块列表。</p>

</section>

<section id="dynamic"><title>将多进程处理模块构建为DSO模块</title>

    <p>在Unix等平台中，多进程处理模块可以构建为DSO模块，并可以以和其他DSO模块相同
    的方式动态加载进服务器中。同时，多进程处理模块构建为DSO模块还可以让你通过
    更新<directive module="mod_so">LoadModule</directive>来修改使用的多进程
    处理模块，而无需重新构建服务器。</p>

    <highlight language="config">
    LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
    </highlight>

    <p>如<directive module="mod_so">LoadModule</directive>中加载了
    多个多进程处理模块，服务器将不能启动，并返回如下错误信息。</p>

    <example>AH00534: httpd: Configuration error: More than one MPM
    loaded.</example>

    <p>此功能可通过<program>configure</program>脚本的<code>--enable-mpms-shared</code>
    选项启用。你可以通过传入参数<code><em>all</em></code>来安装适用于该平台的全部
    多进程处理模块。或者，你可以传入一个带有你所想安装多进程处理模块的列表来设置所要安装的
    多进程处理模块。</p>

    <p>无论是自动选择，还是通过<program>configure</program>脚本的<code>--with-mpm</code>
    选项安装的默认多进程处理模块，都会加载到生成的服务器配置文件中，你可以通过编辑
    <directive module="mod_so">LoadModule</directive>来选择不同的多进程处理模块。</p>

</section>

</manualpage>
