如果你在Heroku上的一个dyno上设置了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
答案 0 :(得分:1)
当然可以 - 阅读http://bugsplat.info/2011-11-27-concurrency-on-heroku-cedar.html。我自己没试过,但我很快就会。从本质上讲,你最终会得到一个看起来像
的unicorn.rbworker_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基本上没有收入,但他们没有采取任何措施来阻止这种行为(我认为不会这样)。