Class: LoadRampUp

Inherits:
Object
  • Object
show all
Defined in:
lib/load/load_ramp_up.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_id, target_code, configuration) ⇒ LoadRampUp

Returns a new instance of LoadRampUp.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/load/load_ramp_up.rb', line 10

def initialize(run_id, target_code, configuration)
  puts "Load Ramp Up created"
  if (run_id == nil)
  end
  @pids = []
  @run_id = run_id
  @target_code = target_code
  @factory = TestFactory.new
  @tests = {}
  @all_tests = []
  @configuration = configuration
  wasp_id = 0

  @configuration[:tests].each do |test_config|
    test_class = test_config[:test]
    ramp_up_config = test_config[:ramp_up]
    final_count = ramp_up_config[:final]
    @tests[test_class] = []
    while (@tests[test_class].length < final_count)
      #                       (run_id, node_id, wasp_id, test, schedule_events, messenger)
      test = @factory.create_test(test_class, @target_code, test_config)
      load_test = LoadTest.new(self, run_id, nil, wasp_id, test, test_config, messenger)
      wasp_id += 1
      @tests[test_class] << load_test
      @all_tests << load_test
    end
    assign_schedules_to_tests(test_config,  @tests[test_class])
  end
  send_schedule_to_server(@configuration)
end

Instance Attribute Details

#testsObject (readonly)

Returns the value of attribute tests.



7
8
9
# File 'lib/load/load_ramp_up.rb', line 7

def tests
  @tests
end

Instance Method Details

#assign_schedules_to_tests(test_config, load_tests) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/load/load_ramp_up.rb', line 83

def assign_schedules_to_tests(test_config, load_tests)
  ramp_up = test_config[:ramp_up]
  initial_count = test_config[:initial]

  load_tests.each do |test|
    test.schedule.add(0, :pause)
  end

  (0..initial_count - 1).each do |index|
    test = load_tests[index]
    test.schedule.add(0, :run)
  end

  rate = ramp_up[:rate]
  current_time = 0
  tests_started = initial_count
   while (tests_started < ramp_up[:final]) do
     current_time += rate
     load_tests[tests_started].schedule.add(current_time, :run)
     tests_started += 1
   end

   sustain_time = test_config[:sustain]
   current_time += sustain_time

   ramp_down = test_config[:ramp_down]
   final_count = ramp_down[:final]
   rate = ramp_down[:rate]
   while (tests_started > final_count) do
     load_tests[tests_started - 1].schedule.add(current_time, :pause)
     tests_started -= 1
     current_time += rate
   end
end

#durationObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/load/load_ramp_up.rb', line 56

def duration
  last_time = 0
  @all_tests.each do |test|
    test_last_time = test.duration
    if (test_last_time > last_time)
      last_time = test_last_time
    end
  end
  return last_time
end

#find_total_loadsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/load/load_ramp_up.rb', line 68

def find_total_loads
  load_at_times
  time = 0
  while (!done) do
    count = 0
    @all_tests.each do |test|
      if (test.current_action(time) == :run)
        count += 1
      end
    end
    time += 1
  end
end

#kill_pids(pids) ⇒ Object



150
151
152
153
154
155
# File 'lib/load/load_ramp_up.rb', line 150

def kill_pids(pids)
  puts "Killing child processes"
  pids.each do |pid|
    Process.kill("INT", pid)
  end
end

#runObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/load/load_ramp_up.rb', line 120

def run
  begin
     puts "Running Load test"
     @configuration[:tests].each do |test_config|
       test_name = test_config[:name]
       puts "Starting test: #{test_name}"
       @tests[test_name].each do |load_test|
         @pids << fork {
           #puts "Launching test: #{test_name} : #{load_test.wasp_id}"
           load_test.run
         }
       end
     end
     wait_for_kill_signal()
  rescue Interrupt => e
    puts "Interrupt signal received, quitting.  [#{e.class.name}]   #{e.message}"
  ensure
    kill_pids(@pids)
  end
  exit 0
end

#send_schedule_to_server(configuration) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/load/load_ramp_up.rb', line 42

def send_schedule_to_server(configuration)
  (0..duration).each do |time|
    total_load = 0
    @all_tests.each do |test|
      action = test.schedule.current_action(time)
      if (action == :run)
        total_load += 1
      end
    end
    report_load_to_server(@run_id, time, total_load)
  end
end

#wait_for_kill_signalObject



143
144
145
146
147
# File 'lib/load/load_ramp_up.rb', line 143

def wait_for_kill_signal()
  while (true) do
    sleep 2000
  end
end