mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
FEATURE: configurable connection reaping settings
This commit is contained in:
parent
cdef67667a
commit
d56b71851b
2 changed files with 25 additions and 7 deletions
|
@ -289,21 +289,32 @@ module Discourse
|
|||
nil
|
||||
end
|
||||
|
||||
def self.start_connection_reaper(interval=30, age=30)
|
||||
def self.start_connection_reaper
|
||||
return if GlobalSetting.connection_reaper_age < 1 ||
|
||||
GlobalSetting.connection_reaper_interval < 1
|
||||
|
||||
# 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)
|
||||
begin
|
||||
sleep GlobalSetting.connection_reaper_interval
|
||||
reap_connections(GlobalSetting.connection_reaper_age)
|
||||
rescue => e
|
||||
Discourse.handle_exception(e, {message: "Error reaping connections"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.reap_connections(age)
|
||||
pools = []
|
||||
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool}
|
||||
|
||||
pools.each do |pool|
|
||||
pool.drain(age.seconds)
|
||||
end
|
||||
end
|
||||
|
||||
def self.sidekiq_redis_config
|
||||
{ url: $redis.url, namespace: 'sidekiq' }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue