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:
parent
5bea933370
commit
805120fc95
3 changed files with 11 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue