Class: AutoScale
- Inherits:
-
Object
- Object
- AutoScale
- Defined in:
- lib/auto_scale.rb
Defined Under Namespace
Modules: LOAD_LISTENER
Constant Summary collapse
- LOAD_DECREMENT_FACTOR =
2x times
2
Instance Attribute Summary collapse
-
#current_pid_switch ⇒ Object
Returns the value of attribute current_pid_switch.
-
#current_workers_count ⇒ Object
Returns the value of attribute current_workers_count.
-
#high_load ⇒ Object
Returns the value of attribute high_load.
-
#interrupted ⇒ Object
Returns the value of attribute interrupted.
-
#previous_pid_switch ⇒ Object
Returns the value of attribute previous_pid_switch.
-
#previous_workers_count ⇒ Object
Returns the value of attribute previous_workers_count.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#stopped ⇒ Object
Returns the value of attribute stopped.
Instance Method Summary collapse
- #exit ⇒ Object
- #increment_or_decrement ⇒ Object
- #jobs_count ⇒ Object
- #monitor ⇒ Object
- #monitor_workers ⇒ Object
- #start(count) ⇒ Object
- #stop(count) ⇒ Object
Instance Attribute Details
#current_pid_switch ⇒ Object
Returns the value of attribute current_pid_switch.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def current_pid_switch @current_pid_switch end |
#current_workers_count ⇒ Object
Returns the value of attribute current_workers_count.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def current_workers_count @current_workers_count end |
#high_load ⇒ Object
Returns the value of attribute high_load.
12 13 14 |
# File 'lib/auto_scale.rb', line 12 def high_load @high_load end |
#interrupted ⇒ Object
Returns the value of attribute interrupted.
12 13 14 |
# File 'lib/auto_scale.rb', line 12 def interrupted @interrupted end |
#previous_pid_switch ⇒ Object
Returns the value of attribute previous_pid_switch.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def previous_pid_switch @previous_pid_switch end |
#previous_workers_count ⇒ Object
Returns the value of attribute previous_workers_count.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def previous_workers_count @previous_workers_count end |
#queue ⇒ Object
Returns the value of attribute queue.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def queue @queue end |
#stopped ⇒ Object
Returns the value of attribute stopped.
10 11 12 |
# File 'lib/auto_scale.rb', line 10 def stopped @stopped end |
Instance Method Details
#exit ⇒ Object
53 54 55 |
# File 'lib/auto_scale.rb', line 53 def exit stop self.current_workers_count end |
#increment_or_decrement ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/auto_scale.rb', line 57 def increment_or_decrement if jobs_count > 0 load = LoadMonitor.can_increase_load?(self.max_cpu_load, self.max_memory_load) self.current_workers_count += self.increment_step if(load && self.previous_workers_count < self.max_workers) self.current_workers_count -= self.decrement_step if(!load && self.previous_workers_count > self.min_workers) self.current_workers_count = 0 if self.current_workers_count < 0 else self.current_workers_count = self.min_workers end scale_workers sleep(self.sleep_time) end |
#jobs_count ⇒ Object
49 50 51 |
# File 'lib/auto_scale.rb', line 49 def jobs_count ScaleWorkers.configuration.count_procedure(self.queue, self.max_failure) end |
#monitor ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/auto_scale.rb', line 14 def monitor bind_interrupt_listener usage_listener = bind_high_usage_listener monitor_workers ensure Thread.kill(usage_listener) if usage_listener end |
#monitor_workers ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/auto_scale.rb', line 22 def monitor_workers loop do begin if self.interrupted exit break elsif self.high_load high_load_decrement scale_workers self.high_load = false else increment_or_decrement end rescue Exception => e self.interrupted = true end end end |
#start(count) ⇒ Object
45 46 47 |
# File 'lib/auto_scale.rb', line 45 def start(count) ScaleWorkers.configuration.start_procedure(self.queue, count) end |
#stop(count) ⇒ Object
41 42 43 |
# File 'lib/auto_scale.rb', line 41 def stop(count) ScaleWorkers.configuration.stop_procedure(self.queue, count) end |