我的RubyOnRails应用程序使用Apache配置背后的通常一组mongrel进行设置.我们注意到我们的Mongrel Web服务器内存使用量在某些操作上会变得非常大,我们真的希望能够随时动态地重新启动选定的Mongrel进程.
但是,由于我不会进入这里的原因,我们有时非常重要的是我们不会在处理请求时中断Mongrel,因此我假设一个简单的进程终止不是答案.
理想情况下,我想向Mongrel发送一个信号,表示"完成你正在做的任何事情然后在接受任何更多连接之前退出".
是否有标准技术或最佳实践?
我已经做了一点调查的杂种源和事实证明,杂种狗安装一个信号处理器来捕获一个标准过程杀(项),做一个正常关机,所以我并不需要特殊的程序毕竟.
您可以在处理请求时杀死Mongrel时从日志输出中看到此信息.例如:
** TERM signal received. Thu Aug 28 00:52:35 +0000 2008: Reaping 2 threads for slow workers because of 'shutdown' Waiting for 2 requests to finish, could take 60 seconds.Thu Aug 28 00:52:41 +0000 2008: Reaping 2 threads for slow workers because of 'shutdown' Waiting for 2 requests to finish, could take 60 seconds.Thu Aug 28 00:52:43 +0000 2008 (13051) Rendering layoutfalsecontent_typetext/htmlactionindex within layouts/application
看看使用monit.您可以根据内存或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.