FEATURE: configurable connection reaping settings
This commit is contained in:
parent
cdef67667a
commit
d56b71851b
|
@ -108,3 +108,10 @@ rtl_css = false
|
||||||
# this is global so it is easier to set in multisites
|
# this is global so it is easier to set in multisites
|
||||||
# TODO allow for global overrides
|
# TODO allow for global overrides
|
||||||
new_version_emails = true
|
new_version_emails = true
|
||||||
|
|
||||||
|
# connection reaping helps keep connection counts down, postgres
|
||||||
|
# will not work properly with huge numbers of open connections
|
||||||
|
# reap connections from pool that are older than 30 seconds
|
||||||
|
connection_reaper_age = 30
|
||||||
|
# run reap check every 30 seconds
|
||||||
|
connection_reaper_interval = 30
|
||||||
|
|
|
@ -289,21 +289,32 @@ module Discourse
|
||||||
nil
|
nil
|
||||||
end
|
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
|
# this helps keep connection counts in check
|
||||||
Thread.new do
|
Thread.new do
|
||||||
while true
|
while true
|
||||||
sleep interval
|
begin
|
||||||
pools = []
|
sleep GlobalSetting.connection_reaper_interval
|
||||||
ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool}
|
reap_connections(GlobalSetting.connection_reaper_age)
|
||||||
|
rescue => e
|
||||||
pools.each do |pool|
|
Discourse.handle_exception(e, {message: "Error reaping connections"})
|
||||||
pool.drain(age.seconds)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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
|
def self.sidekiq_redis_config
|
||||||
{ url: $redis.url, namespace: 'sidekiq' }
|
{ url: $redis.url, namespace: 'sidekiq' }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue