今天测试遇到一个问题,apache 对新的链接一直没有响应,而旧的链接还能工做。apache
查看 apache 错误日志,有一个日志记录:ide
AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
一直没有留意过 apache 的链接配置,看错误的信息,应该是链接数超过了 apache 的某个配置。测试
查一下 apache 的链接状况.net
lsof -i -n -P | grep apache2
看结果不少链接了。因而,查了一下,找到了 apache 的 MPM 工做模式的介绍 http://blog.csdn.net/STFPHP/article/details/52954303 ,
修改加大了 prefork 的链接限制:线程
<IfModule mpm_prefork_module> StartServers 10 MinSpareServers 5 MaxSpareServers 20 MaxRequestWorkers 100 MaxConnectionsPerChild 10000 </IfModule>
其中 MaxConnectionsPerChild
为进程处理了多少了链接以后进行回收,有助力于减小内存泄漏。日志
除了 prefork 模式,apache 还支持 worker 和 event 模式。 worker 模式混合使用了进程和线程,event 则更进一步(event is based on the worker MPM)。
在event 模式下,链接只在活跃时才分配 worker 来处理,其底层采用的是 apache 封装过的非阻塞式 IO。code