Add NewRelic instrumentation for ThinkingSphinx
NewRelic provides a really great mechanism in their plugin to instrument just about anything.
One of the things I found when analyzing actions in NewRelic was that all of the time that was being spent in the ThinkingSphinx methods were being attributed to the template instead of the model. As we all know, mis-attribution of time spent can make tracking down trouble spots in your code much more difficult.
It ends up that all that is required to start tracking the time you are searching in ThinkingSphinx is a couple calls to add_method_tracer
:
add_method_tracer :search, 'ActiveRecord/#{self.name}/search'
add_method_tracer :search, 'ActiveRecord/search', :push_scope => false
add_method_tracer :search, 'ActiveRecord/all', :push_scope => false
You can see the full code here.
Once you’ve required the code, you’ll start to see the #search
and #search_count
methods show up in your Performance Breakdowns:
Isn’t that sweet?
Update: NewRelic has some great documentation for Custom Metric Collection if you want to do more.