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

Add Rails Profiler #2

Closed
simeonwillbanks opened this issue Dec 10, 2013 · 3 comments
Closed

Add Rails Profiler #2

simeonwillbanks opened this issue Dec 10, 2013 · 3 comments

Comments

@simeonwillbanks
Copy link
Owner

Busted should wrap a Rails request and log cache invalidations.

# config/initializers/busted.rb
Busted.run profiler: :rails
[Cache Invalidations] method=0 constant=1
Completed 200 OK in 141.6ms (Views: 108.3ms | ActiveRecord: 2.2ms)

OR

method_cache_invalidations=0 constant_cache_invalidations=1
Completed 200 OK in 141.6ms (Views: 108.3ms | ActiveRecord: 2.2ms)
@spectralblu
Copy link

This looks abandoned. Have you started on this at all, and/or is there any source for this for me to look into? Currently investigating some cache invalidation performance issues and found this gem.

@simeonwillbanks
Copy link
Owner Author

@spectralblu First, thanks for stopping by! Second, I haven't worked on Busted; it is true. Sorry!

I think we can use middleware. Maybe something like this:

# lib/middleware/busted_tracer.rb
require "busted"

module Middleware
  class BustedTracer

    def initialize(app)
      @app = app
    end

    def call(env)
      Busted.start
      response = @app.call(env)
      Busted.finish
      #=> {:invalidations=>{:method=>0, :constant=>1}}
      response
    end
  end
end
# config/application.rb
require File.expand_path('../../lib/middleware/busted_tracer', __FILE__)

module MyApp
  class Application < Rails::Application
    # Maybe there is a better place to insert `Middleware::BustedTracer`?
    config.middleware.insert_after(ActionDispatch::Static, Middleware::BustedTracer)
  end
end

I borrowed this middleware configuration from a personal WIP/proof of concept project called rails-request-2-docs.

If I remember correctly, you'd have to curl a Rails action a few times before it "stabilized." By "stabilized", I mean the middleware output/trace was the same. I'm guessing, this would also be true for cache invalidations, but I haven't tried the above code.

If you get something working or need a bit of help, please let me know! Maybe you can craft a Pull Request? Thanks!

@simeonwillbanks
Copy link
Owner Author

@HParker and I tried this out, and Rails caused some confusing results, so we decided to keep Busted focused and not add a Rails profiler.

See full details in #16.

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

No branches or pull requests

2 participants