Last active
October 14, 2015 17:47
-
-
Save kares/2af272d2dee3b60ec1e0 to your computer and use it in GitHub Desktop.
AR 3.2 pool patch for less contention on release_connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do | |
def release_connection(with_id = current_connection_id) | |
#synchronize do | |
conn = @reserved_connections.delete(with_id) | |
checkin conn, true if conn | |
#end | |
end | |
def checkin(conn, on_release = nil) | |
synchronize do | |
conn.run_callbacks :checkin do | |
conn.expire | |
@queue.signal | |
end | |
release conn unless on_release | |
end | |
end | |
def release(conn) | |
#synchronize do | |
thread_id = nil | |
if @reserved_connections[current_connection_id] == conn | |
thread_id = current_connection_id | |
else | |
thread_id = @reserved_connections.keys.find { |k| | |
@reserved_connections[k] == conn | |
} | |
end | |
@reserved_connections.delete thread_id if thread_id | |
#end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment