From 9ceb0556bceb4f612a3b3eec3ef2ee6f149ef74f Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 11 Aug 2014 16:46:47 +1000 Subject: [PATCH] PERF: add connection pool drainer to keep connection counts down --- config/initializers/99-drain_pool.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 config/initializers/99-drain_pool.rb diff --git a/config/initializers/99-drain_pool.rb b/config/initializers/99-drain_pool.rb new file mode 100644 index 00000000000..e926753f265 --- /dev/null +++ b/config/initializers/99-drain_pool.rb @@ -0,0 +1,13 @@ +# 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