ruby-on-rails-3.1 - 是否可以让一个 Unicorn 子进程处理一个队列,而其余的进程在 Heroku 单个 Dyno 上处理 Web 请求?

标签 ruby-on-rails-3.1 heroku resque unicorn

如果您在 Heroku 上的单个 dyno 上设置了 Unicorn,假设有 3 个 worker 。
是否可以让 2 个子工处理 Web 请求,让 1 个 Unicorn 子执行后台作业,例如 resque 队列或计划任务?

或者这只是不合适?

现在开始工作了!

好的,所以使用下面的答案我设法让它拿起提示,但首先需要一些修补。这对我有用。

配置文件

web: bundle exec unicorn_rails -p $PORT -c config/unicorn.rb

unicorn .rb
worker_processes 2
preload_app true
timeout 30

@resque_pid = nil

before_fork do |server, worker|
  @resque_pid ||= spawn("bundle exec rake environment resque:work QUEUE=*")
end

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end

最佳答案

这当然是可能的 - 阅读 http://bugsplat.info/2011-11-27-concurrency-on-heroku-cedar.html .我自己还没有尝试过,但我很快就会尝试。本质上,你最终会得到一个 unicorn.rb 看起来像

worker_processes 3
timeout 30

@resque_pid = nil

before_fork do |server, worker|
  @resque_pid ||= spawn("bundle exec rake " + \
  "resque:work QUEUES=scrape,geocode,distance,mailer")
end

我不完全确定“适当性”,因为这意味着 Heroku 基本上会失去收入,但他们没有采取任何措施来阻止这种行为(我认为他们也不会)。

关于ruby-on-rails-3.1 - 是否可以让一个 Unicorn 子进程处理一个队列,而其余的进程在 Heroku 单个 Dyno 上处理 Web 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8907281/

相关文章:

ruby-on-rails - state_machine vs aasm gems在Rails 3.2上的应用程序 ruby

ruby-on-rails - ruby rails : Multiple Same Input Fields in Same Form

ruby-on-rails-3 - Capybara-Webkit关闭webkit_server

postgresql - 多个无法从客户端接收数据 : Connection reset by peer Postgresql and Resque

ruby-on-rails - 选择标签在 rails 3.1 rc4 中包含空白行为

ruby-on-rails - 在 Heroku 上更新到 Rails 3.1 时的 Assets 管道

node.js - 使用带有 Node.js 的 postgres+sequelize 的控制台?

ruby-on-rails - Heroku 预编译 Assets 失败

activerecord - 数据库配置没有指定适配器(Sinatra + Heroku + Activerecord)

ruby - 知道 resque worker 何时完成工作