Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: display activerecord query cache hits #393

Closed
wants to merge 1 commit into from

Conversation

gregmolnar
Copy link
Contributor

Based on @nateberkopec 's recommendation, this change would display the Active Record queries hitting its query cache.

@codecov-io
Copy link

codecov-io commented Jul 17, 2019

Codecov Report

Merging #393 into master will decrease coverage by 0.74%.
The diff coverage is 35.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #393      +/-   ##
==========================================
- Coverage   88.76%   88.01%   -0.75%     
==========================================
  Files          21       21              
  Lines        1237     1252      +15     
==========================================
+ Hits         1098     1102       +4     
- Misses        139      150      +11
Impacted Files Coverage Δ
lib/mini_profiler/timer_struct/page.rb 90% <ø> (ø) ⬆️
lib/mini_profiler/timer_struct/request.rb 97.01% <100%> (ø) ⬆️
lib/mini_profiler/asset_version.rb 100% <100%> (ø) ⬆️
lib/mini_profiler/profiler.rb 83.47% <26.66%> (-2.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc2620b...568844a. Read the comment docs.

@gregmolnar gregmolnar changed the title display activerecord query cache hits WIP: display activerecord query cache hits Jul 17, 2019
@gregmolnar gregmolnar force-pushed the query_cache branch 2 times, most recently from c672c26 to b8b7517 Compare July 18, 2019 05:25
@@ -76,6 +76,35 @@ def initialize(app, config = nil)
@config.storage_instance = @config.storage.new(@config.storage_options)
end
@storage = @config.storage_instance
if defined?(ActiveSupport)
ActiveSupport::Notifications.subscribe "sql.active_record" do |*args|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadly this is far from a zero cost thing @nateberkopec , in fact at Discourse we do stuff like this:

https://github.com/discourse/discourse/blob/b5705348b32fff406d8e7e3463def65eaf635206/config/initializers/300-perf.rb#L3-L12

I am ok with adding this stuff to rack-mini-profiler, but we are going to new a setting here and to default it off explaining that this adds cost if you turn it on.

Ideally we should measure what the actual cost of this extra subscriber is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

I wonder if there's a better way to get this stuff, because all we care about is the caller locations when QueryCache is hit. We don't actually have to subscribe to all AR notifications.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with adding this stuff to rack-mini-profiler, but we are going to new a setting here and to default it off explaining that this adds cost if you turn it on.

I mean this is fine with me too tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a configuration option and default it to be off.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally it would be in pp=help and work the same way no-backtrace, normal-backtrace and full-backtrace does. Maybe call it no-ar-cache (default), show-ar-cache (option).

That way you could still use it in production and just flip it back off when you're done. You can unsubscribe from ActiveSupport notifications, right?

@SamSaffron
Copy link
Member

SamSaffron commented Jul 31, 2019 via email

@guiracine
Copy link

Hi! I see that this PR is 3 years old, should it be closed ? I just started to use the profiler and I was looking for a way to distinguish queries that have hit or no hit on the cache.

@nateberkopec
Copy link
Collaborator

Now that RMP subscribes to sql notifications anyway, maybe this PR has new legs...

@prostko
Copy link

prostko commented Aug 29, 2022

Ship it! :)

@nateberkopec
Copy link
Collaborator

Closing as stale but this is a good idea so I'm moving it to an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants