
[英]how do i set up a load balanced Rails web server using mongrel, lighttpd and iis on windows 2003
[英]How do I gracefully shut down a Mongrel web server
我的RubyOnRails应用程序使用Apache配置背后的通常一组mongrel进行设置。 我们注意到我们的Mongrel Web服务器内存使用量在某些操作上会变得非常大,我们真的希望能够随时动态地重新启动选定的Mongrel进程。
但是,由于我不会进入这里的原因,我们有时非常重要的是我们不会在处理请求时中断Mongrel,因此我假设一个简单的进程终止不是答案。
理想情况下,我想向Mongrel发送一个信号,表示“完成你正在做的任何事情然后在接受任何更多连接之前退出”。
是否有标准技术或最佳实践?
我对Mongrel源进行了一些调查,结果发现Mongrel安装了一个信号处理程序来捕获标准进程终止(TERM)并进行正常关闭,所以毕竟我不需要特殊的程序。
您可以在处理请求时杀死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.
更好的问题是如何防止你的应用程序消耗如此多的内存,以至于它需要你不时重启mongrels。
www.modrails.com显着减少了我们的内存占用
沼泽:
如果您正在运行一个进程,它将正常关闭(为其队列中的所有请求提供服务,如果您使用适当的负载平衡,则应该只有1)。 问题是,在旧服务器死亡之前,您无法启动新服务器,因此您的用户将在负载均衡器中排队。 我发现成功的是一个'级联'或滚动重启的杂种。 而不是将它们全部停止并全部启动(因此排队请求直到完成一个杂种,停止,重新启动并接受连接),您可以停止然后按顺序启动每个杂种,阻止调用重新启动下一个杂种,直到前一个杂种为止。备份(使用真正的HTTP检查到/状态控制器)。 当你的杂种滚动时,一次只有一个被关闭,而你正在服务于两个代码库 - 如果你不能这样做,你应该抛出维护页面一分钟。 您应该能够使用capistrano或任何部署工具自动执行此操作。
所以我有3个任务:cap:deploy - 传统的重启同时使用一个钩子来创建一个维护页面,然后在HTTP检查后将其关闭。 cap:deploy:rolling - 它在整个机器上级联(我从iClassify拉出来知道给定机器上有多少个mongrel)没有维护页面。 cap deploy:迁移 - 执行维护页面+迁移,因为“实时”运行迁移通常是个坏主意。
尝试使用:
mongrel_cluster_ctl stop
您还可以使用:
mongrel_cluster_ctl restart
有个问题
当/ usr / local / bin / mongrel_rails cluster :: start --only 8000被触发时会发生什么?
这个特定过程提供的所有请求到底是什么? 还是他们流产了?
我很好奇是否可以在不影响最终用户的情况下完成整个启动/重启的事情......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.