JustinLove / autoscaler

Start/stop Sidekiq workers on Heroku
226 stars 42 forks source link

How to use LinearScalingStrategy? #54

Closed ardell closed 8 years ago

ardell commented 9 years ago

I'm not sure exactly how to set up my middleware chain to use the LinearScalingStrategy with DelayedShutdown. Here's what I've got so far, but it only ever scales to 1 worker dyno, even when I add 10+ jobs. Sidekiq's concurrency is set to 1.

# Only auto-scale on Heroku
if ENV['HEROKU_API_KEY'] and ENV['HEROKU_APP']
  Sidekiq.configure_client do |config|
    config.client_middleware do |chain|
      heroku   = Autoscaler::HerokuScaler.new
      strategy = Autoscaler::DelayedShutdown.new(
        Autoscaler::LinearScalingStrategy.new(10, 1),
        60
      )
      Autoscaler::Sidekiq::Client
        .add_to_chain(chain, 'default' => heroku)
        .set_initial_workers(strategy)
    end
  end

  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      strategy = Autoscaler::DelayedShutdown.new(
        Autoscaler::LinearScalingStrategy.new(10, 1),
        60
      )
      chain.add(Autoscaler::Sidekiq::Server, Autoscaler::HerokuScaler, strategy)
    end
  end
end

What am I doing wrong?

JustinLove commented 9 years ago

Have you checked your worker for errors? I think in the server setup you need Autoscaler::HerokuScaler.new