【发布时间】:2015-01-19 02:30:57
【问题描述】:
有时,每当我在收到以下错误后不久向 Heroku 推送版本时(我正在运行 2 512MB dynos):
2014-11-21 00:38:30.216
188 <45>1 2014-11-21T00:38:29.163459+00:00 heroku web.2 - - Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
我正在使用 unicorn 应用服务器,不幸的是,每个 512MB dyno 的每个 unicorn 工作者只有 1 个(因为在其高峰期,我的应用 RSS 为 320MB - 是的,去算一下,正在发生一些膨胀)。不确定这是否有帮助,但我在 Cedar14 上启用了 Preboot。 UNICORN_WORKERS 设置为 1。
这是我的独角兽设置。我应该关心这个错误吗?
当我们讨论这个话题时,对于我的 2 个 dynos,数据库池大小 15 是否太大(我使用的是允许多达 120 个并发连接的 Postgres 标准)。
worker_processes Integer(ENV['UNICORN_WORKERS'] || 2)
timeout Integer(ENV['UNICORN_TIMEOUT'] || 25)
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
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
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
# other settings
if defined?(ActiveRecord::Base)
config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = Integer(ENV['DB_REAPING_FREQUENCY'] || 10)
config['pool'] = ENV['DB_POOL'] || 15
ActiveRecord::Base.establish_connection(config)
end
end
【问题讨论】:
-
关于上述配置的附注。真的
DB_POOL在独角兽世界中应该是 1 或 2(每个工作进程的连接数)。因此最好有ENV['DB_POOL'] || 2。
标签: heroku unicorn heroku-postgres