Apache-2.2
Apache2:伺服器達到 MaxClients 設置,考慮提高 MaxClients 設置
我在使用 APC 的專用 Ubuntu 12.04 LTS (Apache/2.2.22)、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 的配置(它是一個 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 執行一些壓力測試,看看我是否可以重現它……不走運。:(
編輯:我剛剛做了一個大發現:
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 之前,您需要將“硬程式碼”“硬編碼”到 apache 的原始碼中,以將限制從 256 增加到大約 2048