diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-05-18 11:43:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-18 11:43:16 +0300 |
commit | 1f89d432c52a357598da8a3033d31f84b92f8b8c (patch) | |
tree | b9511b0b2569de86ac7fe28f4261dece851b7c86 /activerecord | |
parent | aa7da0471f7fcf2adbbc26c37a25914d8493928d (diff) | |
parent | 3e2e8eeb9ea552bd4782538cf9348455f3d0e14a (diff) | |
download | rails-1f89d432c52a357598da8a3033d31f84b92f8b8c.tar.gz rails-1f89d432c52a357598da8a3033d31f84b92f8b8c.tar.bz2 rails-1f89d432c52a357598da8a3033d31f84b92f8b8c.zip |
Merge pull request #36296 from jhawthorn/dont_fear_the_reaper
Use a single thread for all ConnectionPool Reapers
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 68498b5dc5..4ff3cb0071 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -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 |