我使用Unicorn(4.5.0)将一个rails应用程序部署到Heroku Celadon雪松堆栈,其中包含以下unicorn.rb文件:
worker_processes 2 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
check_client_connection true
在看似随机的时间,它使用的服务(包括DB)unicorns没有任何明显的变化,将进入重启循环。他们将继续重启,并出现以下典型错误:
ERROR -- : worker=0 PID:935 timeout (31s > 30s), killing
问题在于每个独角兽工作者每30秒重启一次。它在底层dyno重新启动时停止,因此我猜它与unicorn主进程和heroku交互的方式有关。
其他任何遇到这种情况的人或者对于可能的原因有什么想法?
答案 0 :(得分:0)
您不应使用check_client_connection true
选项。
根据Heroku Unicorn documentation,你应该使用这样的配置文件:
# config/unicorn.rb
worker_processes 3
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end