Skip to content

Instantly share code, notes, and snippets.

@carimura
Created October 19, 2015 20:52
Show Gist options
  • Save carimura/f17536adc57fbff87032 to your computer and use it in GitHub Desktop.
Save carimura/f17536adc57fbff87032 to your computer and use it in GitHub Desktop.
run.rb
require 'iron_worker_ng'
client = IronWorkerNG::Client.new
start = Time.now
tasks = !ARGV[0].nil? ? ARGV[0].to_i : 5
threads = !ARGV[1].nil? ? ARGV[1].to_i : 1
cluster = !ARGV[2].nil? ? ARGV[2].to_s : "default"
priority = !ARGV[3].nil? ? ARGV[3].to_i : 0
sleep_param = 1
puts "\ntasks #{tasks}, threads #{threads}, cluster #{cluster}, priority #{priority}\n"
tt = []
threads.times.each do |i|
puts "-------- starting thread #{i} --------"
tt << Thread.new{tasks.times{|j| client.tasks.create('basic', {thread: i, num: j, sleep: sleep_param}, {cluster: cluster,priority:priority}); }}
end
tt.map(&:join)
tt.map{ |t| begin; t.join; nil; rescue Exception => e; e.inspect;end;}.compact
totes = Time.now - start
puts "started #{tasks*threads} tasks in #{totes} seconds for an average of #{((totes/tasks)*1000).round(1)}ms each"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment