看看使用监控。您可以根据内存或 CPU 使用情况动态重启 mongrel。这是我为我的客户编写的配置文件中的一行。
check process mongrel-8000 with pidfile /var/www/apps/fooapp/current/tmp/pids/mongrel.8000.pid
start program = "/usr/local/bin/mongrel_rails cluster::start --only 8000"
stop program = "/usr/local/bin/mongrel_rails cluster::stop --only 8000"
if totalmem is greater than 150.0 MB for 5 cycles then restart # eating up memory?
if cpu is greater than 50% for 8 cycles then alert # send an email to admin
if cpu is greater than 80% for 5 cycles then restart # hung process?
if loadavg(5min) greater than 10 for 3 cycles then restart # bad, bad, bad
if 3 restarts within 5 cycles then timeout # something is wrong, call the sys-admin
if failed host 192.168.106.53 port 8000 protocol http request /monit_stub
with timeout 10 seconds
then restart
group mongrel
然后,您将为所有 mongrel 集群实例重复此配置。monit_stub 行只是一个 monit 尝试下载的空文件。如果不能,它也会尝试重新启动实例。
注意:资源监控似乎不适用于带有 Darwin 内核的 OS X。