nve*_*rba 5 heroku unicorn resque ruby-on-rails-3.1
如果你在Heroku上的一个dyno上设置了Unicorn,那就说3个工人.是否有可能让2个子工作者处理Web请求,1个Unicorn子进行后台作业,例如resque队列或计划任务?
或者那是不合适的?
现在搞定了!
好的,所以使用下面的答案,我设法得到它来获取提示,但它首先需要一些修修补补.这对我有用.
Procfile
web: bundle exec unicorn_rails -p $PORT -c config/unicorn.rb
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
这当然是可能的 - 请阅读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
Run Code Online (Sandbox Code Playgroud)
我并不完全确定“适当性”,因为这意味着 Heroku 本质上正在损失收入,但他们没有采取任何措施来阻止这种行为(我认为他们也不会)。