From 82d2777a4222deb746467783eb0226ad60d307e7 Mon Sep 17 00:00:00 2001 From: "Jason R. Clark" Date: Thu, 12 Mar 2015 11:31:51 -0700 Subject: [PATCH] RUBY-1454 Modify connection lookup for makara Based on https://github.com/taskrabbit/makara/issues/59, there were perf issues in looking up the connection from the pool when on ActiveRecord 4.x using the makara adapter. While this was a problem with makara itself, @mnelson suggested alternate lookup code which works with makara and actually allocates less, so we're updating to use that. --- .../instrumentation/active_record_subscriber.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/active_record_subscriber.rb b/lib/new_relic/agent/instrumentation/active_record_subscriber.rb index 8435055140..a46df96972 100644 --- a/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +++ b/lib/new_relic/agent/instrumentation/active_record_subscriber.rb @@ -78,8 +78,16 @@ def record_metrics(event, config) #THREAD_LOCAL_ACCESS def active_record_config_for_event(event) return unless event.payload[:connection_id] - connections = ::ActiveRecord::Base.connection_handler.connection_pool_list.map { |handler| handler.connections }.flatten - connection = connections.detect { |cnxn| cnxn.object_id == event.payload[:connection_id] } + connection = nil + connection_id = event.payload[:connection_id] + + ::ActiveRecord::Base.connection_handler.connection_pool_list.each do |handler| + connection = handler.connections.detect do |conn| + conn.object_id == connection_id + end + + break if connection + end connection.instance_variable_get(:@config) if connection end