Sha256: d65ec89eccb8158954b04824430e717d120304b2bc2c2f1df6de600915844a83
Contents?: true
Size: 1.04 KB
Versions: 49
Compression:
Stored size: 1.04 KB
Contents
module Bench class Runner include Logging include Timer attr_reader :threads def initialize @threads = [] @sessions = [] end def test(concurrency,iterations,&block) thread_id = 0 total_time = time do concurrency.times do sleep rand(2) thread = Thread.new(block) do |t| tid, iteration = thread_id,0 iterations.times do s = Session.new(tid,iteration) @sessions << s begin yield Bench,s rescue Exception => e puts "error running script: #{e.inspect}" end iteration += 1 end end thread_id += 1 threads << thread end begin threads.each { |t| t.join } rescue RestClient::RequestTimeout => e logger.info "Request timed out #{e}" end end Bench.sessions = @sessions Bench.total_time = total_time end end end
Version data entries
49 entries across 49 versions & 1 rubygems