2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FEATURE: add connnection reaping based on maximum age

This feature ensures connections to the db are always attempted to be closed
after 600 seconds of idle time.
This commit is contained in:
Sam 2015-10-17 11:29:16 +11:00
parent 5bea933370
commit 805120fc95
3 changed files with 11 additions and 8 deletions

View file

@ -340,7 +340,7 @@ module Discourse
while true
begin
sleep GlobalSetting.connection_reaper_interval
reap_connections(GlobalSetting.connection_reaper_age)
reap_connections(GlobalSetting.connection_reaper_age, GlobalSetting.connection_reaper_max_age)
rescue => e
Discourse.handle_exception(e, {message: "Error reaping connections"})
end
@ -348,12 +348,12 @@ module Discourse
end
end
def self.reap_connections(age)
def self.reap_connections(idle, max_age)
pools = []
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool}
pools.each do |pool|
pool.drain(age.seconds)
pool.drain(idle.seconds, max_age.seconds)
end
end