错误R12(退出超时)使用Heroku推荐的Unicorn配置 [英] Error R12 (Exit timeout) using Heroku's recommended Unicorn config

查看:112
本文介绍了错误R12(退出超时)使用Heroku推荐的Unicorn配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的独角兽配置(从 Heroku的文档复制):

 #config / unicorn.rb 
worker_processes整数(ENV [WEB_CONCURRENCY] || 3)
timeout 30
preload_app true

before_fork | server,worker |
Signal.trap'TERM'do
把'Unicorn master拦截TERM并发送自己QUIT',而不是'
Process.kill'QUIT',Process.pid
end

定义了?(ActiveRecord :: Base)和
ActiveRecord :: Base.connection.disconnect!
结束

after_fork | server,worker |
Signal.trap'TERM'do
让'独角兽工人拦截TERM并且什么也不做。等待主发送QUIT'
结束

定义?(ActiveRecord :: Base)和
ActiveRecord :: Base.establish_connection
结束

但是每次测试重新开始时,我们都会得到这个结果:

  heroku web.5  -   - 错误R12(退出超时) - >至少有一个进程在SIGTERM 

Ruby 2.0,Rails 3.2,Unicorn 4.6的10秒内未能退出。 3

解决方案

我们已经有一段时间与Unicorn有过类似的问题。 。 。我们也会看到随机超时错误,尽管我们从来没有看到太多的负载,并有4个工作站,每个工作站有4个工作站(我们从来没有任何请求排队)。即使在Heroku的帮助下,我们也幸运地摆脱了这些错误。我感觉即使他们对Heroku上Unicorn的最佳设置也没有100%的自信。



我们刚刚转投Puma,到目前为止这么好,好多了性能和没有奇怪的超时了。我们转换到Puma的其他原因之一是,我怀疑我们的一些随机超时来自慢速客户端。 。 。独角兽的目的不是为了应对慢速客户。



如果我们看到Puma继续取得成功,我会告诉您,但目前为止这么好。假设你的应用程序是线程安全的,该开关非常轻松。



以下是我们正在使用的puma设置。我们正在使用集群模式。



procfile:

  web :bundle exec puma -p $ PORT -C ./config/puma.rb 

puma.rb:

 环境ENV ['RACK_ENV'] 
线程整型(ENV [PUMA_THREADS] || 5),Integer (ENV [PUMA_THREADS] || 5)

整数(ENV [WEB_CONCURRENCY] || 4)
preload_app!

on_worker_boot do
ActiveSupport.on_load(:active_record)do
ActiveRecord :: Base.establish_connection
end
end


我们目前有 WEB_CONCURRENCY 设置为4, PUMA_THREADS 设置为5。



我们不使用DB_POOL的初始化程序,只使用5的默认DB_POOL设置(因此为5个线程)。

我们使用 WEB_CONCURRENCY 作为我们的环境变量名的唯一原因是,log2viz报告了正确的工人数。宁愿将它称为 PUMA_WORKERS ,但无论如何,这都不是什么大问题。

希望这会有所帮助。 。 。再次,将让你知道,如果我们看到任何问题与彪马。


My Unicorn config (copied from Heroku's docs):

# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 30
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

But every time a dyno is restarted, we get this:

heroku web.5 - - Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM

Ruby 2.0, Rails 3.2, Unicorn 4.6.3

解决方案

We've had issues like this with Unicorn for some time . . . we also get seemingly random timeout errors, even though we never see much load and have 4 dynos with 4 workers each (we never have any request queuing). We have had 0 luck getting rid of these errors, even with help from Heroku. I get the feeling even they aren't 100% confident in the optimal settings for Unicorn on Heroku.

We just recently switched to Puma and so far so good, much better performance and no weird timeouts yet. One of the other reasons we switched to Puma is that I suspect some of our random timeouts come from "slow clients" . . . Unicorn isn't designed to handle slow clients.

I will let you know if we see continued success with Puma, but so far so good. The switch is pretty painless, assuming your app is thread-safe.

Here are the puma settings we are using. We are using "Clustered Mode".

procfile:

web: bundle exec puma -p $PORT -C ./config/puma.rb

puma.rb:

environment ENV['RACK_ENV']
threads Integer(ENV["PUMA_THREADS"] || 5),Integer(ENV["PUMA_THREADS"] || 5)

workers Integer(ENV["WEB_CONCURRENCY"] || 4)
preload_app!

on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end

We currently have WEB_CONCURRENCY set to 4 and PUMA_THREADS set to 5.

We aren't using an initializer for DB_POOL, just using the default DB_POOL setting of 5 (hence the 5 threads).

The only reason we are using WEB_CONCURRENCY as our environment variable name is so that log2viz reports the correct number of workers. Would rather call it PUMA_WORKERS but whatever, not a huge deal.

Hope this helps . . . again, will let you know if we see any issues with Puma.

这篇关于错误R12(退出超时)使用Heroku推荐的Unicorn配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆