Sha256: 8b6fda14020766616b107148f36172e22a8921cab55ff1d0879ea632b099b284
Contents?: true
Size: 1.02 KB
Versions: 39
Compression:
Stored size: 1.02 KB
Contents
require 'spec_helper' describe Queue do include QueueTest let :thread_num do 5 end let :loop_num do 50 end let :now do Time.now.to_i end def thread_main thread_id = Thread.current.object_id loop_num.times do |i| queue.submit("#{thread_id}-#{i}", "type01", {}, :now=>now-10) task = queue.poll(:now=>now, :alive_time=>60) task.should_not == nil task.heartbeat!(:now=>now, :alive_time=>70) task.finish!(:now=>now, :retention_time=>80) end end it 'stress' do puts "stress test with threads=#{thread_num} * loop_num=#{loop_num} = #{thread_num * loop_num} tasks" # initialize queue here queue now start_at = Time.now (1..thread_num).map { Thread.new(&method(:thread_main)) }.each {|thread| thread.join } finish_at = Time.now elapsed = finish_at - start_at task_num = thread_num * loop_num puts "#{elapsed} sec." puts "#{task_num / elapsed} req/sec." puts "#{elapsed / task_num} sec/req." end end
Version data entries
39 entries across 39 versions & 1 rubygems