# Apache下的MPM模式

## Apache的prefork模式

prefork采用预派生子进程方式，用单独的子进程来处理 不同的请求，进程之间彼此独立。在make编译和make install安装后，使用httpd -l来确定当前使用的MPM是prefork.c。查看httpd-mpm.conf配置文件，里面包含如下默认的配置段：

```
<IfModule prefork.c>
    StartServers 5                  #初始化进程数量
    MinSpareServers 5          #空闲进程总数最小值
    MaxSpareServers 10        #空闲进程总数最大值
    MaxClients 150                #最大客户端连接数量限制
    MaxRequestsPerChild 0   #子进程将能处理的请求数量
</IfModule>
```

## Apache的worker模式

worker全新的支持多线程和多进程混合模型的MPM。由于 使用线程来处理，所以可以处理相对海量的请求，而系统资源的开销要小于基于进程的服务器。但是，worker也使用了多进程，每个进程又生成多个线程。

```
<IfModule worker.c>
    ServerLimit 25        #每个子进程可配置的线程数上限
    ThreadLimit 200     #所有服务线程总数的硬限制
    StartServers 3 
    MaxClients 2000（2.3.13后改为MaxRequestWorkers）
    MinSpareThreads 50 
    MaxSpareThreads 200 
    ThreadsPerChild 100   #每个子进程建立的线程数
    MaxRequestsPerChild 0 (MaxConnectionsPerChild)
</IfModule>
```

Apache的event模式

Event是Work模式的优化，主要为了解决Worker模式处理KeepAlive连接性能差的缺陷。通过建立专用处理线程来处理KeepAlive连接，同时将活跃请求转发给其他线程。避免了KeepAlive带来的灾难。

```
<IfModule event.c>
    StartServers 3
    MinSpareThreads 75
    MaxSpareThreads 250
    ThreadsPerChild 25
    MaxRequestWorkers 400
    MaxConnectionsPerChild 0
</IfModule>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://phper.shujuwajue.com/phpxuan-xiang-he-yun-xing-yuan-li/apachede-mpm-mo-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
