Skip to content

Instantly share code, notes, and snippets.

@kares
Last active October 14, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kares/2af272d2dee3b60ec1e0 to your computer and use it in GitHub Desktop.
Save kares/2af272d2dee3b60ec1e0 to your computer and use it in GitHub Desktop.
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