aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorDevin Christensen <quixoten@gmail.com>2017-04-12 14:45:10 -0600
committerDevin Christensen <quixoten@gmail.com>2017-04-12 14:45:10 -0600
commit3360742396a00c9e2ff9838373788bed432d5ea7 (patch)
treee2a2dd25c3ecfb70a0bee44789aa70bee9921c66 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parent92ba89dbcc3fd22296434103503a28dbf6b63789 (diff)
downloadrails-3360742396a00c9e2ff9838373788bed432d5ea7.tar.gz
rails-3360742396a00c9e2ff9838373788bed432d5ea7.tar.bz2
rails-3360742396a00c9e2ff9838373788bed432d5ea7.zip
Switch to LIFO for the connection pool
Using a FIFO for the connection pool can lead to issues when there are upstream components (pgbouncer, haproxy, etc.) that terminate connections that are idle after a period of time. Switching to a LIFO reduces the probability that a thread will checkout a connection that is about to be closed by an idle timeout in an upstream component.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb4
1 files changed, 2 insertions, 2 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 53dbbd8c21..ea76ff983e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -80,7 +80,7 @@ module ActiveRecord
# * private methods that require being called in a +synchronize+ blocks
# are now explicitly documented
class ConnectionPool
- # Threadsafe, fair, FIFO queue. Meant to be used by ConnectionPool
+ # Threadsafe, fair, LIFO queue. Meant to be used by ConnectionPool
# with which it shares a Monitor. But could be a generic Queue.
#
# The Queue in stdlib's 'thread' could replace this class except
@@ -111,7 +111,7 @@ module ActiveRecord
# Add +element+ to the queue. Never blocks.
def add(element)
synchronize do
- @queue.push element
+ @queue.unshift element
@cond.signal
end
end