Commit 693cb4a6 by Jim Abramson

Merge pull request #66 from edx/feature/jsa/track-slowdowns

Feature/jsa/track slowdowns
parents 31ef160d d2473e9e
require 'new_relic/agent/method_tracer'
get "#{APIPREFIX}/search/threads" do get "#{APIPREFIX}/search/threads" do
sort_key_mapper = { sort_key_mapper = {
...@@ -50,11 +52,15 @@ get "#{APIPREFIX}/search/threads" do ...@@ -50,11 +52,15 @@ get "#{APIPREFIX}/search/threads" do
num_pages = results.total_pages num_pages = results.total_pages
page = [num_pages, [1, page].max].min page = [num_pages, [1, page].max].min
{ json_output = nil
collection: collection, self.class.trace_execution_scoped(['Custom/get_search_threads/json_serialize']) do
num_pages: num_pages, json_output = {
page: page, collection: collection,
}.to_json num_pages: num_pages,
page: page,
}.to_json
end
json_output
end end
end end
......
require 'new_relic/agent/method_tracer'
post "#{APIPREFIX}/users" do post "#{APIPREFIX}/users" do
user = User.new(external_id: params["id"]) user = User.new(external_id: params["id"])
user.username = params["username"] user.username = params["username"]
...@@ -43,11 +45,15 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id| ...@@ -43,11 +45,15 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
collection = presenter.to_hash_array(true) collection = presenter.to_hash_array(true)
collection = author_contents_only(collection, user_id) collection = author_contents_only(collection, user_id)
{ json_output = nil
collection: collection, self.class.trace_execution_scoped(['Custom/get_user_active_threads/json_serialize']) do
num_pages: num_pages, json_output = {
page: page, collection: collection,
}.to_json num_pages: num_pages,
page: page,
}.to_json
end
json_output
end end
......
...@@ -66,6 +66,21 @@ if RACK_ENV.to_s != "test" # disable api_key auth in test environment ...@@ -66,6 +66,21 @@ if RACK_ENV.to_s != "test" # disable api_key auth in test environment
end end
end end
if ENV["ENABLE_IDMAP_LOGGING"]
after do
idmap = Mongoid::Threaded.identity_map
vals = {
"pid" => Process.pid,
"dyno" => ENV["DYNO"],
"request_id" => params[:request_id]
}
idmap.each {|k, v| vals["idmap_count_#{k.to_s}"] = v.size }
logger.info vals.map{|e| e.join("=") }.join(" ")
end
end
# Enable the identity map. The middleware ensures that the identity map is # Enable the identity map. The middleware ensures that the identity map is
# cleared for every request. # cleared for every request.
Mongoid.identity_map_enabled = true Mongoid.identity_map_enabled = true
......
...@@ -182,11 +182,15 @@ helpers do ...@@ -182,11 +182,15 @@ helpers do
collection = pres_threads.to_hash_array(bool_recursive) collection = pres_threads.to_hash_array(bool_recursive)
end end
{ json_output = nil
collection: collection, self.class.trace_execution_scoped(['Custom/handle_threads_query/json_serialize']) do
num_pages: num_pages, json_output = {
page: page, collection: collection,
}.to_json num_pages: num_pages,
page: page,
}.to_json
end
json_output
end end
end end
...@@ -285,5 +289,14 @@ helpers do ...@@ -285,5 +289,14 @@ helpers do
error 503 error 503
end end
end end
include ::NewRelic::Agent::MethodTracer
add_method_tracer :user
add_method_tracer :thread
add_method_tracer :comment
add_method_tracer :flag_as_abuse
add_method_tracer :unflag_as_abuse
add_method_tracer :author_contents_only
add_method_tracer :handle_threads_query
end end
require 'new_relic/agent/method_tracer'
require_relative 'content' require_relative 'content'
class CommentThread < Content class CommentThread < Content
...@@ -143,11 +144,15 @@ class CommentThread < Content ...@@ -143,11 +144,15 @@ class CommentThread < Content
#unforutnately, we cannot paginate here, b/c we don't know how the ordinality is totally #unforutnately, we cannot paginate here, b/c we don't know how the ordinality is totally
#unrelated to that of threads #unrelated to that of threads
c_results = search.results c_results = comment_ids = comments = thread_ids = nil
self.class.trace_execution_scoped(['Custom/perform_search/collect_comment_search_results']) do
comment_ids = c_results.collect{|c| c.id}.uniq c_results = search.results
comments = Comment.where(:id.in => comment_ids) comment_ids = c_results.collect{|c| c.id}.uniq
thread_ids = comments.collect{|c| c.comment_thread_id} end
self.class.trace_execution_scoped(['Custom/perform_search/collect_comment_thread_ids']) do
comments = Comment.where(:id.in => comment_ids)
thread_ids = comments.collect{|c| c.comment_thread_id}
end
#thread_ids = c_results.collect{|c| c.comment_thread_id} #thread_ids = c_results.collect{|c| c.comment_thread_id}
#as soon as we can add comment thread id to the ES index, via Tire updgrade, we'll #as soon as we can add comment thread id to the ES index, via Tire updgrade, we'll
...@@ -155,13 +160,15 @@ class CommentThread < Content ...@@ -155,13 +160,15 @@ class CommentThread < Content
#use the elasticsearch index instead to avoid DB hit #use the elasticsearch index instead to avoid DB hit
original_thread_ids = results.collect{|r| r.id} self.class.trace_execution_scoped(['Custom/perform_search/collect_unique_thread_ids']) do
original_thread_ids = results.collect{|r| r.id}
#now add the original search thread ids
thread_ids += original_thread_ids #now add the original search thread ids
thread_ids += original_thread_ids
thread_ids = thread_ids.uniq
thread_ids = thread_ids.uniq
end
#now run one more search to harvest the threads and filter by group #now run one more search to harvest the threads and filter by group
search = Tire::Search::Search.new 'comment_threads' search = Tire::Search::Search.new 'comment_threads'
search.filter(:terms, :thread_id => thread_ids) search.filter(:terms, :thread_id => thread_ids)
...@@ -301,5 +308,8 @@ private ...@@ -301,5 +308,8 @@ private
def destroy_subscriptions def destroy_subscriptions
subscriptions.delete_all subscriptions.delete_all
end end
include ::NewRelic::Agent::MethodTracer
add_method_tracer :perform_search
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment