autoscaler 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ - Added Autoscaler::LinearScalingStrategy
6
+ - EntireQueuSystem#queued always returns an integer
7
+
3
8
  ## 0.6.0
4
9
 
5
10
  - Excon errors from the Heroku API are caught be default. See `HerokuScaler#exception_handler` to override behavior
@@ -0,0 +1,30 @@
1
+ module Autoscaler
2
+ # Strategies determine the target number of workers
3
+ # This strategy sets the number of workers to be proportional to the number of enqueued jobs.
4
+ class LinearScalingStrategy
5
+ #@param [integer] workers maximum number of workers to spin up.
6
+ #@param [integer] worker_capacity the amount of jobs one worker can handle
7
+ def initialize(workers = 1, worker_capacity = 25)
8
+ @workers = workers
9
+ @worker_capacity = worker_capacity
10
+ end
11
+
12
+ # @param [QueueSystem] system interface to the queuing system
13
+ # @param [Numeric] event_idle_time number of seconds since a job related event
14
+ # @return [Integer] target number of workers
15
+ def call(system, event_idle_time)
16
+ total_capacity = (@workers * @worker_capacity).to_f
17
+ percent_capacity = total_work(system) / total_capacity
18
+
19
+ ideal_scale = (percent_capacity * @workers).ceil
20
+ max_scale = @workers
21
+
22
+ return [ideal_scale, max_scale].min
23
+ end
24
+
25
+ private
26
+ def total_work(system)
27
+ system.queued + system.scheduled + system.retrying
28
+ end
29
+ end
30
+ end
@@ -12,7 +12,7 @@ module Autoscaler
12
12
 
13
13
  # @return [Integer] amount work ready to go
14
14
  def queued
15
- sidekiq_queues.values.map(&:to_i).reduce(&:+)
15
+ sidekiq_queues.values.map(&:to_i).reduce(&:+) || 0
16
16
  end
17
17
 
18
18
  # @return [Integer] amount of work scheduled for some time in the future
@@ -1,4 +1,4 @@
1
1
  module Autoscaler
2
2
  # version number
3
- VERSION = "0.6.0"
3
+ VERSION = "0.7.0"
4
4
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'test_system'
3
+ require 'autoscaler/linear_scaling_strategy'
4
+
5
+ describe Autoscaler::LinearScalingStrategy do
6
+ let(:cut) {Autoscaler::LinearScalingStrategy}
7
+
8
+ it "deactivates with no work" do
9
+ system = TestSystem.new(0)
10
+ strategy = cut.new(1)
11
+ strategy.call(system, 1).should == 0
12
+ end
13
+
14
+ it "activates with some work" do
15
+ system = TestSystem.new(1)
16
+ strategy = cut.new(1)
17
+ strategy.call(system, 1).should be > 0
18
+ end
19
+
20
+ it "minimally scales with minimal work" do
21
+ system = TestSystem.new(1)
22
+ strategy = cut.new(2, 2)
23
+ strategy.call(system, 1).should == 1
24
+ end
25
+
26
+ it "maximally scales with too much work" do
27
+ system = TestSystem.new(5)
28
+ strategy = cut.new(2, 2)
29
+ strategy.call(system, 1).should == 2
30
+ end
31
+
32
+ it "proportionally scales with some work" do
33
+ system = TestSystem.new(5)
34
+ strategy = cut.new(5, 2)
35
+ strategy.call(system, 1).should == 3
36
+ end
37
+ end
@@ -33,6 +33,10 @@ describe Autoscaler::Sidekiq::EntireQueueSystem do
33
33
  subject.queued.should == 0
34
34
  end
35
35
 
36
+ it "with no work and no queues" do
37
+ subject.queued.should == 0
38
+ end
39
+
36
40
  it "with no scheduled work" do
37
41
  subject.scheduled.should == 0
38
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoscaler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-05 00:00:00.000000000 Z
13
+ date: 2013-12-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sidekiq
@@ -121,6 +121,7 @@ files:
121
121
  - lib/autoscaler/binary_scaling_strategy.rb
122
122
  - lib/autoscaler/delayed_shutdown.rb
123
123
  - lib/autoscaler/heroku_scaler.rb
124
+ - lib/autoscaler/linear_scaling_strategy.rb
124
125
  - lib/autoscaler/sidekiq/activity.rb
125
126
  - lib/autoscaler/sidekiq/celluloid_monitor.rb
126
127
  - lib/autoscaler/sidekiq/client.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/autoscaler/binary_scaling_strategy_spec.rb
140
141
  - spec/autoscaler/delayed_shutdown_spec.rb
141
142
  - spec/autoscaler/heroku_scaler_spec.rb
143
+ - spec/autoscaler/linear_scaling_strategy_spec.rb
142
144
  - spec/autoscaler/sidekiq/activity_spec.rb
143
145
  - spec/autoscaler/sidekiq/celluloid_monitor_spec.rb
144
146
  - spec/autoscaler/sidekiq/client_spec.rb
@@ -177,6 +179,7 @@ test_files:
177
179
  - spec/autoscaler/binary_scaling_strategy_spec.rb
178
180
  - spec/autoscaler/delayed_shutdown_spec.rb
179
181
  - spec/autoscaler/heroku_scaler_spec.rb
182
+ - spec/autoscaler/linear_scaling_strategy_spec.rb
180
183
  - spec/autoscaler/sidekiq/activity_spec.rb
181
184
  - spec/autoscaler/sidekiq/celluloid_monitor_spec.rb
182
185
  - spec/autoscaler/sidekiq/client_spec.rb