Repository is archived
No commit activity in last 3 years
No release in over 3 years
Sidekiq middleware for low-overhead profiling of background jobs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

 Project Readme

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

  1. Fork it ( https://github.com/glassechidna/stackprofiler-sidekiq/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request