是否可以让一个 Unicorn 子进程处理队列,而其余进程则在 Heroku 单 Dyno 上处理 Web 请求?
如果您在 Heroku 上的单个测功机上设置了 Unicorn,例如 3 个工作人员。 是否可以让 2 个子进程处理 Web 请求,并让 1 个 Unicorn 子进程执行后台作业,例如 resque 队列或计划任务?
或者这只是不合适?
现在可以工作了!
好的,所以使用下面的答案我设法让它接受提示,但首先需要进行一些修改。这对我有用。
Procfile
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
If you have Unicorn set up on a single dyno on Heroku, say with 3 workers.
Is it possible to have 2 of the child workers processing web requests, and 1 Unicorn child doing background jobs, such as a resque queue, or scheduled tasks?
Or is that just not appropriate?
Now got it Working!
OK, so using the answer bellow I managed to get it to pick up the cue, but it took a bit of tinkering first. This is what worked for me.
Procfile
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这当然是可能的 - 请阅读 http://bugsplat。信息/2011-11-27-concurrency-on-heroku-cedar.html。虽然我自己还没有尝试过,但我很快就会尝试。本质上,你最终会得到一个 unicorn.rb,看起来
我并不完全确定“适当性”,因为这意味着 Heroku 本质上正在损失收入,但他们没有采取任何措施来阻止这种行为(也没有我想他们会的)。
It certainly is possible - take a read of http://bugsplat.info/2011-11-27-concurrency-on-heroku-cedar.html. I've not tried it myself though but I will be soon. Essentially, you'll end up with a unicorn.rb that looks like
I'm not entirely sure of the 'appropriateness' since it means Heroku is essentially loosing out on revenue but they haven't taken any stops to block this behaviour (nor I think would they).