From f897c89d48ee65f236966d9f15e08fa51fda3b8c Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 11 Aug 2014 17:51:55 +1000 Subject: [PATCH] FIX: run reaper after fork --- config/initializers/99-drain_pool.rb | 13 +------------ lib/discourse.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/config/initializers/99-drain_pool.rb b/config/initializers/99-drain_pool.rb index e926753f265..e26f45976da 100644 --- a/config/initializers/99-drain_pool.rb +++ b/config/initializers/99-drain_pool.rb @@ -1,13 +1,2 @@ # pg performs inconsistently with large amounts of connections -# this helps keep connection counts in check -Thread.new do - while true - sleep 30 - pools = [] - ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool} - - pools.each do |pool| - pool.drain(30.seconds) - end - end -end +Discourse.start_connection_reaper diff --git a/lib/discourse.rb b/lib/discourse.rb index cf471c7c578..7badcc01d51 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -258,9 +258,25 @@ module Discourse Sidekiq.redis_pool.shutdown{|c| nil} # re-establish Sidekiq.redis = sidekiq_redis_config + start_connection_reaper nil end + def self.start_connection_reaper(interval=30, age=30) + # this helps keep connection counts in check + Thread.new do + while true + sleep interval + pools = [] + ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool} + + pools.each do |pool| + pool.drain(age.seconds) + end + end + end + end + def self.sidekiq_redis_config { url: $redis.url, namespace: 'sidekiq' } end