Created
June 15, 2013 09:26
-
-
Save brainopia/5787526 to your computer and use it in GitHub Desktop.
Benchmark limit_fetch overhead in different scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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