Sha256: 95aae728acc67fd206203fbbb5237e9757e7c08219dfcd59412cf82189a150b3

Contents?: true

Size: 1.03 KB

Versions: 15

Compression:

Stored size: 1.03 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)
      expect(task).not_to eq(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

15 entries across 15 versions & 1 rubygems

Version Path
perfectqueue-0.8.54 spec/stress.rb
perfectqueue-0.10.1 spec/stress.rb
perfectqueue-0.8.53 spec/stress.rb
perfectqueue-0.8.52 spec/stress.rb
perfectqueue-0.10.0 spec/stress.rb
perfectqueue-0.8.51 spec/stress.rb
perfectqueue-0.8.50 spec/stress.rb
perfectqueue-0.9.2 spec/stress.rb
perfectqueue-0.9.1 spec/stress.rb
perfectqueue-0.9.0 spec/stress.rb
perfectqueue-0.8.49 spec/stress.rb
perfectqueue-0.8.48 spec/stress.rb
perfectqueue-0.8.47 spec/stress.rb
perfectqueue-0.8.46 spec/stress.rb
perfectqueue-0.8.45 spec/stress.rb