Module: Unicorn::AutoScaling::HttpServer
- Defined in:
- lib/unicorn/auto_scaling/http_server.rb
Overview
Auto scaling extensions for the Unicorn http server
Constant Summary collapse
- RAINDROP_OFFSET =
Unicorn::Worker::PER_DROP - 1
- NONE =
0
- INCREMENT =
1
- DECREMENT =
2
Instance Attribute Summary collapse
-
#autoscale_check_interval ⇒ Object
Returns the value of attribute autoscale_check_interval.
-
#autoscale_idle_time_decrement ⇒ Object
Returns the value of attribute autoscale_idle_time_decrement.
-
#autoscale_idle_time_increment ⇒ Object
Returns the value of attribute autoscale_idle_time_increment.
-
#autoscale_idle_time_samples ⇒ Object
Returns the value of attribute autoscale_idle_time_samples.
-
#autoscale_max_workers ⇒ Object
Returns the value of attribute autoscale_max_workers.
-
#autoscale_min_workers ⇒ Object
Returns the value of attribute autoscale_min_workers.
-
#autoscaling ⇒ Object
Returns the value of attribute autoscaling.
Instance Method Summary collapse
- #init_worker_process(worker) ⇒ Object
- #process_client(client) ⇒ Object
- #reap_all_workers ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#autoscale_check_interval ⇒ Object
Returns the value of attribute autoscale_check_interval.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_check_interval @autoscale_check_interval end |
#autoscale_idle_time_decrement ⇒ Object
Returns the value of attribute autoscale_idle_time_decrement.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_idle_time_decrement @autoscale_idle_time_decrement end |
#autoscale_idle_time_increment ⇒ Object
Returns the value of attribute autoscale_idle_time_increment.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_idle_time_increment @autoscale_idle_time_increment end |
#autoscale_idle_time_samples ⇒ Object
Returns the value of attribute autoscale_idle_time_samples.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_idle_time_samples @autoscale_idle_time_samples end |
#autoscale_max_workers ⇒ Object
Returns the value of attribute autoscale_max_workers.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_max_workers @autoscale_max_workers end |
#autoscale_min_workers ⇒ Object
Returns the value of attribute autoscale_min_workers.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscale_min_workers @autoscale_min_workers end |
#autoscaling ⇒ Object
Returns the value of attribute autoscaling.
11 12 13 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 11 def autoscaling @autoscaling end |
Instance Method Details
#init_worker_process(worker) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 48 def init_worker_process(worker) @_autoscale_time_of_last_request = Time.now.to_f @_autoscale_last_check = Time.now.to_f @_autoscale_idle_times = [] super(worker) end |
#process_client(client) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 16 def process_client(client) autoscale! if self.autoscaling super(client) @_autoscale_time_of_last_request = Time.now.to_f if self.autoscaling end |
#reap_all_workers ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 24 def reap_all_workers if @_autoscale_last_scaling < Time.now.to_f - 10 if @_autoscale_raindrop[RAINDROP_OFFSET] == INCREMENT if self.worker_processes < self.autoscale_max_workers logger.info("Auto scaling: UP") self.worker_processes += 1 end elsif @_autoscale_raindrop[RAINDROP_OFFSET] == DECREMENT if self.worker_processes > self.autoscale_min_workers logger.info('Auto scaling: DOWN') self.worker_processes -= 1 end end @_autoscale_raindrop[RAINDROP_OFFSET] = NONE @_autoscale_last_scaling = Time.now.to_f end super end |
#start ⇒ Object
56 57 58 59 60 |
# File 'lib/unicorn/auto_scaling/http_server.rb', line 56 def start self.autoscale_max_workers ||= self.worker_processes super end |