【问题标题】:Multiple resque workers mode creating extra processes多个 resque worker 模式创建额外的进程
【发布时间】:2011-11-08 12:17:07
【问题描述】:

我需要启动 4 个 resque worker,所以我使用了以下命令

bundle exec rake environment resque:workers RAILS_ENV=production COUNT=4 QUEUE=* VERBOSE=1 PIDFILE=tmp/pids/resque_worker.pid  >> log/resque_worker_QUEUE.log 

但是进入网页界面,它实际上是启动了 8 个工人。有两个父进程,每个进程有 4 个子进程。以下是进程的树视图:

ruby /code_base/bundle/ruby/1.9.1/bin/rake 环境 resque:workers RAILS_ENV=production COUNT=4 QUEUE=* VERBOSE=1 PIDFILE=tmp/pids/resque_worker.pid \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * \_ [红宝石] ruby /code_base/bundle/ruby/1.9.1/bin/rake 环境 resque:workers RAILS_ENV=production COUNT=4 QUEUE=* VERBOSE=1 PIDFILE=tmp/pids/resque_worker.pid \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * | \_ [红宝石] \_ resque-1.15.0: 等待 * \_ [红宝石]

不知道是什么导致额外进程启动?

【问题讨论】:

    标签: resque


    【解决方案1】:

    您不想在生产中使用 COUNT=n 选项,因为它在一个线程中而不是在一个单独的进程中运行每个工作线程 - 这不太稳定。

    官方 Resque 文档:

    Running Multiple Workers
    
    At GitHub we use god to start and stop multiple workers. A sample god configuration file is included under examples/god. We recommend this method.
    
    If you'd like to run multiple workers in development mode, you can do so using the resque:workers rake task:
    
    $ COUNT=5 QUEUE=* rake resque:workers
    This will spawn five Resque workers, each in its own process. Hitting ctrl-c should be sufficient to stop them all.
    

    Here's the example God monitoring/configuration file 与 Resque 一起运行以运行多个进程,以及 here's an example for monit

    【讨论】:

    • 我之前已经浏览过该文档和脚本文件,但我们使用的是 monit。根据该脚本,似乎每个 resque 工作人员在 WORKER_TIMEOUT 时间后被杀死。现在,即使我进行了新的部署,工作人员可能仍然使用旧代码。因此,在最坏的情况下,需要 WORKER_TIMEOUT 时间来为工作人员加载新代码,这有时可能会成为问题。对此有什么想法吗?
    • 只要您使用新部署的代码启动一个新的工作人员,让正在运行的现有工作在杀死工作人员之前完成并没有错。关键是向工作人员发送一个软退出信号,以便在当前运行的作业完成时退出。所以是的,您可以让工作人员运行旧代码,但它的工作是在部署新代码之前开始的。
    • 我看到这种方法的另一个问题是上帝自己失败了。由于工人在 WORKER_TIMEOUT 之后被杀死,因此不会有工人处理作业。
    • 感谢您的回答!几乎放弃使用上帝。当我使用 COUNT=3 和两个工人运行它时,我得到了大量的红宝石。此外,当使用 resque:workers 而不是 resque:work 时,您将失去使用“god stop”命令停止生成的进程/线程的能力。它们仍然会运行,让您头疼不已。
    猜你喜欢
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多