【发布时间】:2013-11-17 02:36:36
【问题描述】:
您好,我们正在 Heroku 的 Cedar 堆栈上运行 Unicorn 和 Sidekiq。我们间歇性地收到以下错误
BurnThis ActiveRecord::StatementInvalid: PG::UnableToSend: SSL SYSCALL error: EOF detected
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() SSL SYSCALL error: Connection timed out
有没有人知道这些错误的直接原因是什么?与我们的数据库的连接太多了吗?我们已经通过以下方式设置了分叉:
独角兽.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
# other setup
if defined?(ActiveRecord::Base)
config = Rails.application.config.database_configuration[Rails.env]
config['adapter'] = 'postgis'
config['pool'] = ENV['DB_POOL'] || 5
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
ActiveRecord::Base.establish_connection(config)
end
end
还有 sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { :url => ENV['REDIS_URL'], :namespace => 'btsidekiq' }
if defined?(ActiveRecord::Base)
config = Rails.application.config.database_configuration[Rails.env]
config['adapter'] = 'postgis'
config['pool'] = ENV['DB_POOL'] || 5
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
ActiveRecord::Base.establish_connection(config)
end
end
Sidekiq.configure_client do |config|
config.redis = { :url => ENV['REDIS_URL'], :namespace => 'btsidekiq' }
end
我们的数据库池大小相当大 DB_POOL=100 并且我们在一个显然支持 500 个并发连接的 PG 数据库上。
【问题讨论】:
-
只是想知道,您是否有具有“高可用性”的 Postgres 计划之一?如此处所示,addons.heroku.com/heroku-postgresql#premium-yanari
-
我在对数据库执行重新启动数据库的操作后看到了这种类型的应用程序错误。重新启动应用程序服务器后,由于重新建立连接,错误就会消失。您是否发现看到错误与运行迁移或其他数据库活动之间有任何关联?
-
你有什么理由在 Unicorn 配置的 after_fork 块中设置你的配置?似乎应该在这些块之外。
-
我得到了类似的东西:
ActiveRecord::StatementInvalid (PG::UnableToSend: SSL connection has been closed unexpectedly
标签: heroku connection-pooling rails-activerecord rails-postgresql heroku-postgres