嗨,我们正在使用独角兽和Sidekiq在Heroku的雪松堆栈上运行。我们间歇地得到以下错误
BurnThis ActiveRecord::StatementInvalid: PG::UnableToSend: SSL SYSCALL error: EOF detected
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() SSL SYSCALL error: Connection timed out
有没有人有任何洞察这些错误的直接原因?是否有太多的连接到我们的数据库?我们已经通过以下方式设置了我们的分岔:
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
# 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,我们在一个PG数据库上,显然同时支持500个连接。
此错误是由您的postgis适配器尝试使用来自ActiveRecord连接池的陈旧/死亡连接引起的。解决这个问题有两种方法:
>连接池大小匹配线程数/进程数
>降低连接收获频率(收费者检查死区连接池,每N秒)
要实现#1,您需要设置适合独角兽和Sidekiq的池大小,这可能有不同的需求。
Unicorn是单线程的,因此每个进程的默认池大小为5个连接是正确的。每个WEB_CONCURRENCY后端独角兽员工最多可以分配5个连接。您应该重置默认池大小,并使用您现有的unicorn.rb:
$> heroku config:set DB_POOL=5
Sidekiq使用了一个非常不同的模型。默认情况下,Sidekiq有一个进程和N个线程。你想要一个比Sidekiq线程数更大的DB池大小。您可以在config / initializers / sidekiq.rb中实现这一点,如下所示:
Sidekiq.configure_server do |config|
pool_size = Sidekiq.options[:concurrency] + 2
config.redis = { :url => ENV['REDIS_URL'], :namespace => 'btsidekiq', :size => pool_size }
if defined?(ActiveRecord::Base)
config = Rails.application.config.database_configuration[Rails.env]
config['adapter'] = 'postgis'
config['pool'] = pool_size
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
ActiveRecord::Base.establish_connection(config)
end
end
我最好的猜测是,使用这么大的100连接池,你更有可能产生死连接。适当调整池的大小应该解决这个问题。
如果这不行,你应该尝试将你的DB_REAP_FREQ减少到5秒。
相关文章
- Heroku错误消息没有检测到Cedar支持的应用程序
- python - Imaplib中的EOF错误
- 日志 - Heroku:如何检查Heroku错误日志?
- ruby-on-rails - Rails 3.2 Postgres保存错误“ActiveRecord :: StatementInvalid:PG ::错误:错误:位置5附近的”T“附近的语法错误”
- angularjs - 错误:检测到AotPlugin但它是错误类的实例
- ContextSwitchDeadlock在C#中检测到错误
- RAID 5检测到写入错误?
- heroku - 当它刚刚为Python设置时,无法检测到set buildpack?
转载注明原文:Heroku Sidekiq:ActiveRecord :: StatementInvalid:PG :: UnableToSend:SSL SYSCALL错误:检测到EOF - 代码日志