class Roma::Test::Stress

Attributes

cnt[R]
num_of_threads[R]
runnable[RW]
tmax[R]
tmin[R]

Public Class Methods

new(th_num) click to toggle source
   # File lib/roma/tools/test-scenario.rb
37 def initialize th_num
38   @cnt = 0
39   @tmax = 0
40   @tmin = 100
41   @num_of_threads = th_num
42   @runnable = true
43 end

Public Instance Methods

start(addr, port) click to toggle source
   # File lib/roma/tools/test-scenario.rb
45 def start addr, port
46   Thread.new {
47     sleep_time=10
48     while @runnable
49       sleep sleep_time
50       printf("qps=%d max=%f min=%f ave=%f\n", @cnt / sleep_time, @tmax, @tmin, sleep_time / @cnt.to_f)
51       @@cnt=0
52       @@tmax=0
53       @@tmin=100
54     end
55   }
56 
57   working_threads = []
58   @num_of_threads.times {
59     working_threads << Thread.new {
60       send_random_reqs addr, port
61     }
62   }
63 end

Private Instance Methods

send_random_reqs(addr, port) click to toggle source
   # File lib/roma/tools/test-scenario.rb
65 def send_random_reqs addr, port
66   rc = Roma::Client::RomaClient.new([ "#{addr}_#{port.to_s}" ])
67   n=1000
68   while @runnable
69     begin 
70       i = rand(n)
71       ts = DateTime.now
72       case rand(3)
73       when 0
74         res = rc.set(i.to_s, 'hoge' + i.to_s)
75         puts "set k=#{i} #{res}" if res==nil || res.chomp != 'STORED'
76       when 1
77         res = rc.get(i.to_s)
78         puts "get k=#{i} #{res}" if res == :error
79       when 2
80         res = rc.delete(i.to_s)
81         puts "del k=#{i} #{res}" if res != 'DELETED' && res != 'NOT_FOUND'
82       end
83       t = (DateTime.now - ts).to_f * 86400.0
84       @tmax=t if t > @tmax
85       @tmin=t if t < @tmin
86       @cnt+=1
87     rescue => e
88       p e
89     end
90   end
91 rescue => e
92   p e
93 end