Sha256: 114c6f4fa803050ab7b431087f014b31f6a143948f079cda990c058d16664fd8
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
$LOAD_PATH << File.expand_path(File.dirname(__FILE__)+"/../lib") require 'perfectqueue' require 'perfectqueue/backend/rdb' require 'perfectqueue/backend/simpledb' class StressTest def initialize(uri, table, npt, thread) @db_proc = Proc.new do PerfectQueue::RDBBackend.new(uri, table) end @db_proc.call.create_tables @npt = npt @thread = thread end class ThreadMain < Thread def initialize(key_prefix, db, num, now) @key_prefix = key_prefix @db = db @num = num @now = now super(&method(:run)) end def run @num.times {|i| @db.submit("#{@key_prefix}-#{i}", "data", @now) token, task = @db.acquire(@now+60) if token == nil puts "acquire failed" next end @db.update(token, @now+70) @db.finish(token, @now+80) } end end def run threads = [] key_prefix = "stress-#{'%08x'%rand(2**32)}" now = Time.now @thread.times {|i| threads << ThreadMain.new("#{key_prefix}-#{i}", @db_proc.call, @npt, now.to_i) } threads.each {|t| t.join } finish = Time.now elapsed = finish - now puts "#{elapsed} sec." puts "#{@npt * @thread / elapsed} req/sec." puts "#{elapsed / (@npt * @thread)} sec/req." end end require 'optparse' op = OptionParser.new op.banner += " <uri> <table>" num = 100 thread = 1 op.on('-n', '--num N', Integer) {|n| num = n } op.on('-t', '--thread N', Integer) {|n| thread = n } begin op.parse!(ARGV) if ARGV.length != 2 puts op.to_s exit 1 end uri = ARGV[0] table = ARGV[1] rescue puts op.to_s puts $! exit 1 end npt = num / thread num = npt * thread puts "num: #{num}" puts "thread: #{thread}" puts "num/thread: #{npt}" t = StressTest.new(uri, table, npt, thread) t.run
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
perfectqueue-0.7.15 | test/stress.rb |