zombocom/derailed_benchmarks

Profiling background jobs

Closed this issue · 3 comments

Is there a way currently to boot a Rails app but not hit any endpoints, instead opting for running specific code paths like a Sidekiq background job?

Right now: Not really. I'm open to some kind of integration though. For me personally I've just written my own scripts in a scratch.rb file and hit it manually. For example forcing a sidekiq job to run in the foreground and wrapping it in stackprof/memoryprofiler/etc.

I did something similar; created a new endpoint that triggered the worker job that I wanted to profile.

The way derailed works is we wrap a method:

https://github.com/schneems/derailed_benchmarks/blob/master/lib/derailed_benchmarks/load_tasks.rb#L116-L131

In theory you could do something like this in your perf.rake

case ENV['DERAILED_BACKGROUND_PROFILE']
when 'sidekiq_job_one'
  def call_app
    hash = { stuff: "here" }
    SideKiqJobOne.new(hash).perform_now
  end
else
  puts "Profiling #{ENV['PATH_TO_HIT']}"
end