Git Product home page Git Product logo

sidekiq-benchmark's Introduction

Sidekiq::Benchmark

Gem Version Ruby

Adds benchmarking methods to Sidekiq workers, keeps metrics and adds tab to Web UI to let you browse them.

Installation

Add this line to your application's Gemfile:

gem 'sidekiq-benchmark'

And then execute:

bundle

Usage

class SampleWorker
  include Sidekiq::Worker
  include Sidekiq::Benchmark::Worker

  def perform(id)
    benchmark.first_metric do
      100500.times do something end
    end

    benchmark.second_metric do
      42.times do anything end
    end

    benchmark.finish
  end
end

class OtherSampleWorker
  include Sidekiq::Worker
  include Sidekiq::Benchmark::Worker

  def perform(id)
    benchmark do |bm|
      bm.some_metric do
        100500.times do
        end
      end

      bm.other_metric do
        something_code
      end

      bm.some_metric do
        # some_metric measure continues
      end
    end
    # if block given, yield and finish
  end

end

Examples

Web UI

Web UI

Testing sidekiq workers

When you use Sidekiq::Testing you must load sidekiq-benchmark/testing to stop saving benchmark data to redis. Just add next code to your test or spec helper:

require 'sidekiq-benchmark/testing'

Contributing

  1. Fork it
  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 new Pull Request

sidekiq-benchmark's People

Contributors

dphase avatar ixti avatar kosmatov avatar severinkaelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sidekiq-benchmark's Issues

Doesn't work with Sidekiq 4.2+: undefined method `register' for Sidekiq::WebApplication:Class

Updating Sidekiq to v4.2.2 prevents sidekiq-benchmark from loading. This error message is displayed:

Bundler::GemRequireError: There was an error while trying to load the gem 'sidekiq-benchmark'.
Gem Load Error is: undefined method `register' for Sidekiq::WebApplication:Class
Backtrace for gem load error is:
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-benchmark-0.4.1/lib/sidekiq-benchmark/web.rb:12:in `registered'
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-4.2.2/lib/sidekiq/web.rb:101:in `register'
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-benchmark-0.4.1/lib/sidekiq-benchmark.rb:4:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
~/Code/my_service/config/application.rb:8:in `<top (required)>'
~/Code/my_service/Rakefile:4:in `require'
~/Code/my_service/Rakefile:4:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load_rakefile'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:686:in `raw_load_rakefile'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:96:in `block in load_rakefile'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:95:in `load_rakefile'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:79:in `block in run'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/bin/rake:23:in `load'
~/.rvm/gems/ruby-2.2.4@my_service/bin/rake:23:in `<main>'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `eval'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `<main>'
Bundler Error Backtrace:
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:in `rescue in block (2 levels) in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:85:in `block (2 levels) in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
~/Code/my_service/config/application.rb:8:in `<top (required)>'
~/Code/my_service/Rakefile:4:in `require'
~/Code/my_service/Rakefile:4:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `eval'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `<main>'
NoMethodError: undefined method `register' for Sidekiq::WebApplication:Class
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-benchmark-0.4.1/lib/sidekiq-benchmark/web.rb:12:in `registered'
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-4.2.2/lib/sidekiq/web.rb:101:in `register'
~/.rvm/gems/ruby-2.2.4@my_service/gems/sidekiq-benchmark-0.4.1/lib/sidekiq-benchmark.rb:4:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
~/.rvm/gems/ruby-2.2.4@global/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
~/Code/my_service/config/application.rb:8:in `<top (required)>'
~/Code/my_service/Rakefile:4:in `require'
~/Code/my_service/Rakefile:4:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `eval'
~/.rvm/gems/ruby-2.2.4@my_service/bin/ruby_executable_hooks:15:in `<main>'

Charts are not loading

Hello

First of all, many thanks for the great gem.

Unfortunately the charts cannot be displayed at the moment.
You can also experience this issue in your sample app.

Screenshot

Tested with Google Chrome Version 85.0.4183.102

image

DevTools Console

Uncaught Error: Must call google.charts.load before google.charts.setOnLoadCallback
    at Object.J.R [as setOnLoadCallback] (jsapi:136)
    at chartkick.js:28
    at chartkick.js:57
Uncaught ReferenceError: Chartkick is not defined
    at benchmarks:128

Add sidekiq 7 support

Hello

Starting with sidekiq 7.0.0 the sidekiq-benchmark gem no longer works. Latest compatible sidekiq version: 6.5.8.

Error when using the gem alongside sidekiq 7.x (e.g. 7.0.0, 7.0.2 etc.):

Failure/Error: benchmark.finish
TypeError: Unsupported command argument type: Time

Resources on sidekiq 7:

Are there any plans to add sidekiq 7 support to this gem? I would like to contribute, but I'm afraid I don't have enough time at the moment.

Thanks a lot.

Kind regards
Severin

cannot load such file -- slim (LoadError)

I get the following exception after adding sidekiq-benchmark to the Gemfile:

/Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- slim (LoadError)
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/web.rb:3:in `<top (required)>'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-benchmark-0.2.0/lib/sidekiq-benchmark.rb:1:in `<top (required)>'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /Users/fredrik/Projects/myapp/config/application.rb:9:in `<top (required)>'
    from /Users/fredrik/Projects/myapp/config/environment.rb:2:in `require'
    from /Users/fredrik/Projects/myapp/config/environment.rb:2:in `<top (required)>'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/cli.rb:197:in `require'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/cli.rb:197:in `boot_system'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/cli.rb:39:in `parse'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sidekiq-2.11.2/bin/sidekiq:7:in `<top (required)>'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/bin/sidekiq:23:in `load'
    from /Users/fredrik/.rbenv/versions/1.9.3-p392/bin/sidekiq:23:in `<main>'

Javascript chartkick.js is not loaded in non rails Heroku app

We have a Sinatra app on Heroku and tried to add this gem. It works fine when running localy but the javascript file chartkick.js fails to load when we deploy it to Heroku. Entering the url (/sidekiq/js/chartkick.js) gives a blank result.
Do you have any idea why?

Overhead and Production Use

Would you recommend using this in Production permanently for monitoring jobs?

Any estimate how much overhead it adds? I have jobs that I'm expecting to execute in < 500ms so it probably won't work too well for me if it adds much more then a ~20ms delay to the jobs.

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Bundler could not find compatible versions for gem "sidekiq"

@kosmatov great gem. Thank you for putting together.

When I try and bundle update sidekiq sidekiq-benchmark I get this:

Bundler could not find compatible versions for gem "sidekiq":
  In Gemfile:
    sidekiq (= 6.1.2)

    sidekiq-benchmark (= 0.7.0) was resolved to 0.7.0, which depends on
      sidekiq (~> 5)

Assuming, because the version tag commit was defined prior to the sidekiq update.

Update for new Redis API

We're getting

Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.

redis.multi do
  redis.get("key")
end

should be replaced by

redis.multi do |pipeline|
  pipeline.get("key")
end

I assume the problem is around multiple commands fired to Redis API soon to be deprecated.

Memory Leak in this gem or in one of it's dependencies.

I used this gem with sidekiq 3.3.3, puma 2.11.1, rails 4.2.0, on heroku cedar-14 stack and ran out of memory within minutes. Removed the gem and everything is working fine now. I don't have time to diagnose or debug it so I just create this issue to warn others in the future.

That being said, this gem did benchmark my sidekiq worker perfectly! ๐Ÿ‘ Thank you!

How to use with sidekiq enterprise

Hello, I would like to use this gem with sidekiq-ent, which I install from the source enterprise.contribsys.com. However, when, in the Gemfile, I add gem 'sidekiq-benchmark' after gem 'sidekiq-ent' within or after the block source "https://<username>:<password>@enterprise.contribsys.com/" do and execute bundle, I get the error "Authentication is required for enterprise.contribsys.com". Any ideas how to get this to work?

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.