Class: LoadRunner::Queue
- Inherits:
-
Object
- Object
- LoadRunner::Queue
- Defined in:
- lib/cl/magic/common/load_runner.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
Returns the value of attribute failures.
Instance Method Summary collapse
-
#initialize(logger = nil) ⇒ Queue
constructor
A new instance of Queue.
- #load(num_threads = 1, &work) ⇒ Object
- #run ⇒ Object
- #run_and_stagger(max_sleep = 10) ⇒ Object
- #run_for_durration(num_seconds, max_sleep = 0) ⇒ Object
Constructor Details
#initialize(logger = nil) ⇒ Queue
Returns a new instance of Queue.
7 8 9 10 11 12 13 14 15 |
# File 'lib/cl/magic/common/load_runner.rb', line 7 def initialize(logger = nil) @logger = logger if logger!=nil # setup @threads = [] @transactions = 0 @num_threads = 1 @failures = 0 end |
Instance Attribute Details
#failures ⇒ Object
Returns the value of attribute failures.
5 6 7 |
# File 'lib/cl/magic/common/load_runner.rb', line 5 def failures @failures end |
Instance Method Details
#load(num_threads = 1, &work) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cl/magic/common/load_runner.rb', line 17 def load(num_threads=1, &work) @num_threads = num_threads @work = work # save work for new threads # create threads num_threads.times do # do work create_thread # log @logger.debug "action=create|name=thread" if @logger!=nil end end |
#run ⇒ Object
32 33 34 35 36 |
# File 'lib/cl/magic/common/load_runner.rb', line 32 def run() @start_time = Time.now start_all wait_until_finished end |
#run_and_stagger(max_sleep = 10) ⇒ Object
38 39 40 41 42 |
# File 'lib/cl/magic/common/load_runner.rb', line 38 def run_and_stagger(max_sleep=10) @start_time = Time.now start_all { rand_sleep(max_sleep) } wait_until_finished end |
#run_for_durration(num_seconds, max_sleep = 0) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cl/magic/common/load_runner.rb', line 44 def run_for_durration(num_seconds, max_sleep=0) @start_time = Time.now # keep them running to_time = Time.now + num_seconds # log @logger.info "action=run_for_durration|until=#{to_time}" if @logger!=nil # durration while (Time.now <= to_time) # start threads @threads.each do |t| break if Time.now > to_time # restart threads if (t.status=="sleep") rand_sleep(max_sleep) t.run end if (t.status==false or t.status == nil) @transactions += 1 @threads.delete t thread = create_thread rand_sleep(max_sleep) thread.run # log @logger.debug "thread_count=#{@threads.count}" if @logger!=nil end end end end |