Class: Roma::Test::Stress

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/tools/test-scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(th_num) ⇒ Stress

Returns a new instance of Stress.



37
38
39
40
41
42
43
# File 'lib/roma/tools/test-scenario.rb', line 37

def initialize th_num
  @cnt = 0
  @tmax = 0
  @tmin = 100
  @num_of_threads = th_num
  @runnable = true
end

Instance Attribute Details

#cntObject (readonly)

Returns the value of attribute cnt.



31
32
33
# File 'lib/roma/tools/test-scenario.rb', line 31

def cnt
  @cnt
end

#num_of_threadsObject (readonly)

Returns the value of attribute num_of_threads.



34
35
36
# File 'lib/roma/tools/test-scenario.rb', line 34

def num_of_threads
  @num_of_threads
end

#runnableObject

Returns the value of attribute runnable.



35
36
37
# File 'lib/roma/tools/test-scenario.rb', line 35

def runnable
  @runnable
end

#tmaxObject (readonly)

Returns the value of attribute tmax.



32
33
34
# File 'lib/roma/tools/test-scenario.rb', line 32

def tmax
  @tmax
end

#tminObject (readonly)

Returns the value of attribute tmin.



33
34
35
# File 'lib/roma/tools/test-scenario.rb', line 33

def tmin
  @tmin
end

Instance Method Details

#start(addr, port) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/roma/tools/test-scenario.rb', line 45

def start addr, port
  Thread.new {
    sleep_time=10
    while @runnable
      sleep sleep_time
      printf("qps=%d max=%f min=%f ave=%f\n", @cnt / sleep_time, @tmax, @tmin, sleep_time / @cnt.to_f)
      @@cnt=0
      @@tmax=0
      @@tmin=100
    end
  }

  working_threads = []
  @num_of_threads.times {
    working_threads << Thread.new {
      send_random_reqs addr, port
    }
  }
end