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:
commit
1f89d432c5
1 changed files with 25 additions and 7 deletions
|
@ -294,15 +294,33 @@ module ActiveRecord
|
||||||
@frequency = frequency
|
@frequency = frequency
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
@@mutex = Mutex.new
|
||||||
return unless frequency && frequency > 0
|
@@pools = {}
|
||||||
Thread.new(frequency, pool) { |t, p|
|
|
||||||
|
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
|
loop do
|
||||||
sleep t
|
sleep t
|
||||||
|
@@mutex.synchronize do
|
||||||
|
@@pools[frequency].each do |p|
|
||||||
p.reap
|
p.reap
|
||||||
p.flush
|
p.flush
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
return unless frequency && frequency > 0
|
||||||
|
self.class.register_pool(pool, frequency)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue