FreeBSD 上跑 Apache 2.2 worker 的方法在「apache22 (worker) + mod_fastcgi + php5-fcgi」這篇寫過了,同樣的架構在 Debian 上跑卻發現比 prefork 還吃記憶體,花了一些時間找,發現是預設的 Stack 太大造成的,所以:
<IfModule mpm_worker_module> ThreadStackSize 65536 ThreadLimit 256 StartServers 1 MaxClients 256 MinSpareThreads 1 MaxSpareThreads 256 ThreadsPerChild 256 MaxRequestsPerChild 0 </IfModule>
加了 ThreadStackSize
這個設定後,每個 thread 的 stack 就會比較小了 (預設超過 1MB,不記得多少了),這個方式跑了一個月後還蠻正常的。
Linux 上面, thread stack size 是看 ulimit -s.
如果是 unlimited, 好像還有別的方式決定default.
我一開始也是用 ulimit (Google 找到的文章介紹的),但這得改 /etc/init.d/ 下的東西,我偏好在 apache 裡面自己改...