Apache2:服务器达到MaxClients设置,考虑提高MaxClients设置

我遇到了专用的Ubuntu 12.04 LTS(Apache / 2.2.22),带有APC的PHP 5.3的问题。

每隔几个小时我就会看到这样的情况

[Fri Aug 17 15:36:51 2012] [error] server reached MaxClients setting, consider raising the MaxClients setting 

这会导致服务器拒绝/拒绝所有连接。

当我去重新启动Apache:

 [Fri Aug 17 15:38:14 2012] [warn] child process 8946 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:14 2012] [warn] child process 7496 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:16 2012] [warn] child process 8946 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:16 2012] [warn] child process 7496 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:18 2012] [warn] child process 8946 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:18 2012] [warn] child process 7496 still did not exit, sending a SIGTERM [Fri Aug 17 15:38:20 2012] [error] child process 8946 still did not exit, sending a SIGKILL [Fri Aug 17 15:38:20 2012] [error] child process 7496 still did not exit, sending a SIGKILL [Fri Aug 17 15:38:21 2012] [notice] caught SIGTERM, shutting down [Fri Aug 17 15:38:21 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache] [Fri Aug 17 15:38:22 2012] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.2 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/1.0.1 configured -- resuming normal operations 

由于这一切开始发生,我提高了Apache的configuration(这是一个6核心的16Gb内存的机器,所以我想我很多)。

 <IfModule mpm_prefork_module> StartServers 8 MinSpareServers 5 MaxSpareServers 10 ServerLimit 500 MaxClients 500 MaxRequestsPerChild 1000 </IfModule> 

服务器只提供PHP(没有静态文件),页面加载不会超过几秒钟…

我一直在看mod_status(只是激活它),但我没有看到什么奇怪的…

 Server uptime: 20 minutes 46 seconds Total accesses: 9206 - Total Traffic: 641 kB CPU Usage: u147.52 s17.21 cu0 cs0 - 13.2% CPU load 7.39 requests/sec - 526 B/second - 71 B/request 2 requests currently being processed, 8 idle workers ___...W__..._W.....__........................................... ................................................................ ................................................................ ................................................................ ................................................................ ................................................................ ................................................................ .................................................... 

我甚至尝试用apache ab来运行一些压力testing,看看能否重现它…没有运气。 🙁

编辑:我刚刚做了一个大发现:

 DEBUG: WARNING - require(): GC cache entry '/var/www/common/revisions/1061/library/core/bootstrap.php' (dev=64513 ino=1577080) was on gc-list for 3601 seconds /var/www/common/revisions/1061/library/core/cache/disk/dao.php (16) 

这个错误是什么导致的问题,我相信这是与APC有关。

看起来问题是APC内存不足或者某些东西(用于存储操作码的文件),导致Apache下载。 当我把内存限制提高到256M( apc.shm_size=256M )时,问题就消失了。

将Apache带到反向代理之后(如nginx,…)在从源代码编译apache之前,需要将“hard-code”放入apache的源代码中,将其从256增加到约2048