Class: Autoscaler::LinearScalingStrategy

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(workers = 1, worker_capacity = 25) ⇒ LinearScalingStrategy

Returns a new instance of LinearScalingStrategy.

Parameters:

  • workers (integer) (defaults to: 1)

    maximum number of workers to spin up.

  • worker_capacity (integer) (defaults to: 25)

    the amount of jobs one worker can handle



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.

Parameters:

  • system (QueueSystem)

    interface to the queuing system

  • event_idle_time (Numeric)

    number of seconds since a job related event

Returns:

  • (Integer)

    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