Sha256: fa76ede774952e072d40eb6c333afa5092e91bfa80eebca2ffb4d826b01b787c
Contents?: true
Size: 1.79 KB
Versions: 16
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) @key_prefix = key_prefix @db = db @num = num super(&method(:run)) end def run @num.times {|i| now = Time.now.to_i @db.submit("#{@key_prefix}-#{i}", "data", now) token, task = @db.acquire(now+60, now) 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) } 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
16 entries across 16 versions & 1 rubygems