Class: Autoscaler::LinearScalingStrategy
- Inherits:
-
Object
- Object
- Autoscaler::LinearScalingStrategy
- Defined in:
- lib/autoscaler/linear_scaling_strategy.rb
Overview
Strategies determine the target number of workers This strategy sets the number of workers to be proportional to the number of enqueued jobs.
Instance Method Summary collapse
-
#call(system, event_idle_time) ⇒ Integer
Target number of workers.
-
#initialize(workers = 1, worker_capacity = 25) ⇒ LinearScalingStrategy
constructor
A new instance of LinearScalingStrategy.
Constructor Details
#initialize(workers = 1, worker_capacity = 25) ⇒ LinearScalingStrategy
Returns a new instance of LinearScalingStrategy.
7 8 9 10 |
# File 'lib/autoscaler/linear_scaling_strategy.rb', line 7 def initialize(workers = 1, worker_capacity = 25) @workers = workers @worker_capacity = worker_capacity end |
Instance Method Details
#call(system, event_idle_time) ⇒ Integer
Returns target number of workers.
15 16 17 18 19 20 21 22 23 |
# File 'lib/autoscaler/linear_scaling_strategy.rb', line 15 def call(system, event_idle_time) total_capacity = (@workers * @worker_capacity).to_f percent_capacity = total_work(system) / total_capacity ideal_scale = (percent_capacity * @workers).ceil max_scale = @workers return [ideal_scale, max_scale].min end |