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

Version Path
perfectqueue-0.8.44.1 spec/stress.rb
perfectqueue-0.8.44 spec/stress.rb
perfectqueue-0.8.43 spec/stress.rb
perfectqueue-0.8.42 spec/stress.rb
perfectqueue-0.8.41 spec/stress.rb
perfectqueue-0.8.40 spec/stress.rb
perfectqueue-0.8.39 spec/stress.rb
perfectqueue-0.8.38 spec/stress.rb
perfectqueue-0.8.37 spec/stress.rb
perfectqueue-0.8.36 spec/stress.rb
perfectqueue-0.8.35 spec/stress.rb
perfectqueue-0.8.34 spec/stress.rb
perfectqueue-0.8.33 spec/stress.rb
perfectqueue-0.8.32 spec/stress.rb
perfectqueue-0.8.31 spec/stress.rb
perfectqueue-0.8.30 spec/stress.rb
perfectqueue-0.8.29 spec/stress.rb
perfectqueue-0.8.28 spec/stress.rb
perfectqueue-0.8.26 spec/stress.rb
perfectqueue-0.8.25 spec/stress.rb