Skip to content

Instantly share code, notes, and snippets.

@kares kares/pool.rb
Last active Oct 14, 2015

Embed
What would you like to do?
AR 3.2 pool patch for less contention on release_connection
::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
You can’t perform that action at this time.