1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36296 from jhawthorn/dont_fear_the_reaper

Use a single thread for all ConnectionPool Reapers
This commit is contained in:
Aaron Patterson 2019-05-18 11:43:16 +03:00 committed by GitHub
commit 1f89d432c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -294,15 +294,33 @@ module ActiveRecord
@frequency = frequency
end
@@mutex = Mutex.new
@@pools = {}
def self.register_pool(pool, frequency) # :nodoc:
@@mutex.synchronize do
if @@pools.key?(frequency)
@@pools[frequency] << pool
else
@@pools[frequency] = [pool]
Thread.new(frequency) do |t|
loop do
sleep t
@@mutex.synchronize do
@@pools[frequency].each do |p|
p.reap
p.flush
end
end
end
end
end
end
end
def run
return unless frequency && frequency > 0
Thread.new(frequency, pool) { |t, p|
loop do
sleep t
p.reap
p.flush
end
}
self.class.register_pool(pool, frequency)
end
end