# Autoscaling Sidekiq Workers

**URL:** <https://community.convox.com/t/autoscaling-sidekiq-workers/772>\
**Category:** Configuration\
**Created:** [August 20, 2020, 8:52pm UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772 "2020-08-20T20:52:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.convox.com/u/chris)\
**Post date:** [August 20, 2020, 8:52pm UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/1 "2020-08-20T20:52:49Z")

</div>

Hi,

Was wondering if anyone has had success autoscaling Sidekiq worker instances based on queue depth? If so I’d love to hear about your experiences.

Looking at the Convox docs I’d assume that I’d need to use something like [this gem](https://github.com/sj26/sidekiq-cloudwatchmetrics) to publish my queue metrics to CloudWatch and then setup the autoscaling targets in my convox.yml?

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.convox.com/u/chris)\
**Post date:** [August 21, 2020, 5:24pm UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/2 "2020-08-21T17:24:04Z")

</div>

To answer my own question, yes, thats how you do it!

Adding the gem to my app got all the metrics feeding direct into CloudWatch, and right now I’m doing simple scaling based on queue depth, appears to be working well:

```
scale:
  count: 1-10
  targets:
    custom:
      Sidekiq/EnqueuedJobs:
        aggregate: max
        value: 500
```

---

<div class="post-metadata">

**Author:** ![nathan.f77](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/nathan.f77/32/256_2.png) [@nathan.f77](https://community.convox.com/u/nathan.f77)\
**Post date:** [August 27, 2020, 6:02pm UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/3 "2020-08-27T18:02:44Z")

</div>

Hi Chris, thanks for sharing this, that’s awesome! I was just scaling my Sidekiq workers based on CPU usage, but this is a much better approach, so I’ll set this up as well. Thanks!

---

<div class="post-metadata">

**Author:** ![miles](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@miles](https://community.convox.com/u/miles)\
**Post date:** [October 20, 2020, 6:20pm UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/4 "2020-10-20T18:20:58Z")

</div>

🙌 this is exactly what I was looking for, thank you!

---

<div class="post-metadata">

**Author:** ![nathan.f77](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/nathan.f77/32/256_2.png) [@nathan.f77](https://community.convox.com/u/nathan.f77)\
**Post date:** [February 23, 2021, 5:54am UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/5 "2021-02-23T05:54:32Z")

</div>

Also thanks for writing up this blog post, it was very helpful! [Autoscaling Sidekiq Workers on Convox](http://sourcebottle.net/autoscaling-sidekiq-workers-on-convox)

I finally got this set up and it seems to be working very well.

---

<div class="post-metadata">

**Author:** ![nathan.f77](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/nathan.f77/32/256_2.png) [@nathan.f77](https://community.convox.com/u/nathan.f77)\
**Post date:** [February 23, 2021, 6:05am UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/6 "2021-02-23T06:05:02Z")

</div>

I’ve been running some tests on my staging server, where I enqueued a large number of jobs:

 ![Screen Shot 2021-02-23 at 7.00.25 PM](https://canada1.discourse-cdn.com/flex029/uploads/convox1/original/1X/2be3ae5040afbbc41ed1d0753e64c15b35476b73.png)

It was able to start all 10 workers (the maximum I set) and reached a steady state, then after 20 minutes it started to stop them one-by-one, and seemed to stop one every 2 minutes. So I think it’s working pretty well! I’m tempted to change some of the intervals, but I think I’ll just keep it like this for now since it seems like a reasonable default.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.convox.com/u/chris)\
**Post date:** [April 27, 2021, 11:55am UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/7 "2021-04-27T11:55:13Z")

</div>

Just a heads up, this appears to have stopped working with a recent rack update.

Now when I go into ECS and look at the AutoScaling policy it has changed to be based on CPU utilization, and also appears to be ignoring the cool down params that have been set.

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/convox1/original/1X/e13a646b02b1fff70e03196c6e38092361742fcd.jpeg)

As a workaround, you’re going to need to go into CloudWatch and create 2 alerts on your EnqueuedJobs metric, one for scaling up, and the other for scaling down, then manually (or via Terraform) add 2 auto scaling policies based on them to scale your worker count up and down.

---

<div class="post-metadata">

**Author:** ![nijeesh.k](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/nijeesh.k/32/216_2.png) [@nijeesh.k](https://community.convox.com/u/nijeesh.k)\
**Post date:** [May 17, 2022, 10:35am UTC](https://community.convox.com/t/autoscaling-sidekiq-workers/772/8 "2022-05-17T10:35:20Z")

</div>

Is there a way that i could scale on a per queue basis, i have a queue named `watermark` so if the number of enqueued jobs goes over a threshold lets say `100` can i autoscale it ?

```auto
sidekiq-worker-watermark:
    command: bundle exec sidekiq -q watermark
    scale:
      count: 1-5
      targets:
        custom:
          Sidekiq/QueueSize:
            aggregate: max
            value: 100
            dimensions:
              QueueName: watermark

```

i tried this, but doest seem to be working

**edit #1**

its working for scale-up, but doesn’t seem to be scaling time even after the default cool-down period has been exceeded

 ![DeepinScreenshot_select-area_20220517173137](https://canada1.discourse-cdn.com/flex029/uploads/convox1/original/1X/fb369e80a01a3607329d230864f9663d90d0e929.jpeg)
