Apache的3种工作模式

  • 2019 年 12 月 12 日
  • 笔记

Apache 的工作模式

Apache有三种工作模式:分别是preforkworkerevent

prefork

(多进程,每个进程产生子进程)

prefork 是一种非线程、与派生的工作模式,用的是进程去处理请求,所以比较容易消耗内存,但是稳定性好,某个进程出现问题不会影响到其他请求。

worker

(多进程,每个进程生成多个线程)

worker是使用多个子进程、每个子进程有多个线程、由于使用的是线程去处理请求,消耗内存小,适合高流量的请求,但是如果某个进程出现问题,那么这个进程下的线程都会出现问题,即稳定性不是很好。

event

event模式,是为解决keep-alive保持长连接出现的一种工作模式,使用keep-alive长连接的时候,某个线程会一直被占用,即使中间没有请求,需要等到超时才会被释放,所以这个时候就出现了event的工作模式就出现了。

如 何 配 置 模 块

查当前工作模式

用命令(httpd -l)查看

worker.c 代表工作在worker 模式下

prefork.c 代表工作在prefork 模式下

配置工作模式

在安装的时候需要指定模式:

[root@localhost httpd-2.4.1]# ./configure --prefix=/usr/local/apache2worker --enable-so --with-mpm=worker  [root@localhost httpd-2.4.1]# make  [root@localhost httpd-2.4.1]# make install

–with-mpm=worker 选项指定工作模式为worker,不指定模式的话,默认为Prefork。

3 种模式解析

配置在…/apache/conf/extra/httpd-mpm.conf文件。

perfork

<IfModule mpm_prefork_module>  StartServers 5  MinSpareServers 5  MaxSpareServers 10  MaxRequestWorkers 250  MaxConnectionsPerChild 0  </IfModule> 

# StartServers

数量的服务器进程开始。

# MinSpareServers

最小数量的服务器进程,保存备用。

# MaxSpareServers

最大数量的服务器进程,保存备用。

# MaxRequestWorkers

最大数量的服务器进程允许开始。

# MaxConnectionsPerChild

最大连接数的一个服务器进程服务。

worker

<IfModule mpm_worker_module>  StartServers 3  MinSpareThreads 75  MaxSpareThreads 250  ThreadsPerChild 25  MaxRequestWorkers 400  MaxConnectionsPerChild 0  </IfModule>

# StartServers

初始数量的服务器进程开始。

# MinSpareThreads

最小数量的工作线程,保存备用。

# MaxSpareThreads

最大数量的工作线程,保存备用。

# ThreadsPerChild

固定数量的工作线程在每个服务器进程。

# MaxRequestWorkers

最大数量的工作线程。

# MaxConnectionsPerChild

最大连接数的一个服务器进程服务。

event

<IfModule mpm_event_module>  StartServers 3  MinSpareThreads 75  MaxSpareThreads 250  ThreadsPerChild 25  MaxRequestWorkers 400  MaxConnectionsPerChild 0  </IfModule> 

# StartServers

初始数量的服务器进程开始。

# MinSpareThreads

最小数量的工作线程,保存备用。

# MaxSpareThreads

最大数量的工作线程,保存备用。

# ThreadsPerChild

固定数量的工作线程在每个服务器进程。

# MaxRequestWorkers 

最大数量的工作线程。

# MaxConnectionsPerChild

最大连接数的一个服务器进程服务。

所谓的世俗伦理,也未必真能指引人们走上正确的道路。大多数情况下,那只是社会上的一般想法,没什么深刻的道理。from《单恋》