Stackprofiler::Sidekiq
Please read the stackprofiler
gem README for background on Stackprofiler
in general.
This is a Sidekiq middleware that makes benchmarking of Sidekiq apps a breeze.
It utilises a fork of the the brilliant stackprof
to enable low-overhead
sampling of Ruby processes.
Installation
Add this line to your application's Gemfile:
gem 'stackprofiler-sidekiq'
And then execute:
$ bundle
Or install it yourself as:
$ gem install stackprofiler-sidekiq
Usage
Sidekiq middleware are helpers that can be included in your background jobs.
The Stackprofiler middleware is Stackprofiler::Sidekiq::Middleware
. It can be
configured like this:
require 'stackprofiler/sidekiq'
Sidekiq.configure_server do |config|
config.server_middleware do |chain|
chain.add Stackprofiler::Sidekiq::Middleware, {
ui_url: 'http://localhost:9260/receive',
predicate: proc do |worker, job, queue|
job['class'] == 'MyBackgroundJob'
end
}
end
end
The :ui_url
option is a URL that points to a running instance of the
Stackprofiler web UI. It is mandatory. Refer to the Stackprofiler gem README
to see how to run this (hint, run stackprofiler
in the terminal).
The :predicate
option is optional. By default, the middleware will profile
every Sidekiq job. This might be undesirable because you want to focus on
only one problematic job and filter out the others. The parameter is a proc
object that receives the same arguments as Sidekiq middleware - see the above
link to determine what these are. Returning a truthy value will have the job
profiled, otherwise it is ignored.
Limitations
Due to limitations in Stackprofx, right now only one job at a time can be profiled. This isn't necessarily as bad as it sounds, but a fix is being worked on.
Contributing
- Fork it ( https://github.com/glassechidna/stackprofiler-sidekiq/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request