Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created June 15, 2013 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainopia/5787526 to your computer and use it in GitHub Desktop.
Save brainopia/5787526 to your computer and use it in GitHub Desktop.
Benchmark limit_fetch overhead in different scenarios
require 'benchmark'
require 'sidekiq/limit_fetch'
require 'sidekiq/cli'
total = ARGV.shift || 50
concurrency = ARGV.shift || 1
limit = ARGV.shift
total = total.to_i
limit &&= limit.to_i
class FastJob
include Sidekiq::Worker
sidekiq_options queue: :inline
def perform(i)
puts "job N#{i} is finished"
end
end
class FinishJob
include Sidekiq::Worker
sidekiq_options queue: :inline
def perform
Process.kill 'INT', 0
end
end
FinishJob.perform_async
total.times {|i| FastJob.perform_async total-i }
Sidekiq::Queue['inline'].limit = limit
Sidekiq::CLI.instance.tap do |cli|
%w(validate! boot_system).each {|stub| cli.define_singleton_method(stub) {}}
cli.parse ['-q inline', "-c #{concurrency}"]
puts Benchmark.measure {
begin
cli.run
rescue Exception
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment