Giter Club home page Giter Club logo

stackprofiler-sidekiq's Introduction

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

stackprofiler-sidekiq's People

Contributors

aidansteele avatar

Stargazers

Jon Williams avatar

Watchers

 avatar Benjamin Dobell avatar James Cloos avatar Daniel Whyte avatar  avatar

stackprofiler-sidekiq's Issues

Only one job at a time can be profiled

Fairly serious limitation as per the title. The reason is stack stackprof[x] was not meant to be invoked simultaneously from multiple threads.

Option A:

We could profile all threads (rather than limiting to Thread#current as we do right now) and filter out stack traces that didn't include the iseq for the sidekiq job. Potential problems:

  • If there's 25+ busy threads, we'd be recording a lot of data only to drop most of it as soon as the profiling is done. Might be slow?
  • If the same job is run multiple times concurrently, how do we know which job to attribute the stack traces to? Could get messed up results.

Option B:

Significant rework to the stackprofx fork to support multiple invocations simultaneously. Could group stack traces by thread and have no leakage across threads. Cons: quite a bit of work. I'm lazy.

Right now this limitation is enforced by code in 3427fd4 to ensure nothing funky happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.