Level up your Heroku autoscaling in 15 minutes
Tags: heroku, rails, python, webdev
Published: 2022-04-05 12:31:34

One of the most powerful features of Dynoscale’s Heroku autoscaling is the ability to configure it to meet the needs of your app without needing to write complex code. This tutorial will show you how to make advanced use of Dynoscale’s [Heroku autoscaling](https://dynoscale.net) to meet the needs of your app’s unique performance requirements. It will also show you how to enable the highest levels of autoscaling for your app with just a few configuration steps.

This post covers advanced Heroku autoscaling topics that build upon a [prior post covering the basics](https://dynoscale.net/blog/how-to-setup-heroku-autoscaling-in-under-15-minutes).

Tuning Web Request Queuing
--------------------------

For a great end-user experience on your website, lowering backend latency is crucial. Amazon discovered ten years ago that every 100ms of latency cost them 1% in sales. Google discovered that adding 0.5 seconds to the generation time of a search page [reduced traffic by 20%](http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html). We can match the correct thresholds for your traffic to reduce queue time by spending a few minutes examining the Web Dyno Activity report. Your users and customers will be able to load a page of your site faster if the queue time is reduced.

![Nearing Upper Threshold](https://dynoscale.net/assets/blog/advanced_autoscaling_1-fb9b1eff71bbc2c79796bc906a189d9c51af109d02bbc70f3a2daa9f94c532e1.png) Navigate to the Web Dyno Activity report. Dynoscale sets your web upscale and downscale thresholds to 100 and 50 milliseconds, respectively, by default. These are useful settings, but it's possible that your application has a unique traffic pattern, in which case different thresholds would improve your autoscaling. Take the case above: the queue time was high from 1:00 AM to 1:30 AM, however the auto upscale was not triggered. This means that queries in the p95 category experienced roughly 100 milliseconds of additional backend request time due to queue time.

![Adjusting Upper Threshold](https://dynoscale.net/assets/blog/advanced_autoscaling_2-83dc0d46c44fb9e7917524ea360f6411518e49384f28e401b3d5aaf5b8a81d7f.png) In this case, I recommend lowering the upscale threshold to 90ms and monitoring to see if auto scaling performance improves. Keep in mind not to overfit your thresholds based on a specific scenario. This frequently results in completely unanticipated behavior outside of the specific scenario.

Cost cutting during known periods of lower traffic
--------------------------------------------------

Imagine a scenario where your application provides a service for business users who mostly use it during weekdays. On weekends, your application receives significantly less traffic and you would like to run one web dyno instead of two during this period to cut costs.

![New Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_3-63a7a172cebd122f1d9b3741c6f1e8e833591f78ab40c390874f18c644678af6.png) Navigate to Web Dyno Auto Scaling Page and create a new rule.

![Create New Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_4-5513a1763a27836734ded1539e49a1fe45d0e83f6006dc59e499f15c90ec71e4.png) In the new rule set the lower dyno bound to one and match the upper bound to the default rule’s. Set the Start At and End At to "12:00:00 AM" and "11:59:59 PM", respectively, and the Day of Week to "Weekend". Click Save to commit the rule and downscale to one dyno on weekends.

Preparing for a period of planned higher traffic
------------------------------------------------

Consider a scenario in which your app's marketing team is about to launch a major campaign at 10 a.m. the next day (a Tuesday). You need to increase the dyno ranges to four and eight for a twelve-hour period to ensure the application can manage the increased traffic.

![Create New Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_5-63a7a172cebd122f1d9b3741c6f1e8e833591f78ab40c390874f18c644678af6.png) In advance of the campaign, navigate to Web Dyno Auto Scaling Page and create a new rule.

![Edit Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_6-9f6ca30278aa43792c43468abda3740e2aca993e51449003fcaa4b8ae2332a5e.png) In the new rule set the lower dyno bound to four and the upper bound to eight. Next, set the Day of Week to "Tuesday" and the Start At and End At to "10:00:00 AM" and "10:00:00 PM" respectively. Click Save to create the new rule.

Once the campaign has run its course, delete this new auto scaling rule.

Optimizing for cost savings over traffic demand
-----------------------------------------------

When analyzing the Web Dyno Activity report, it may become clear that small bursts of traffic are driving your application to auto scale up. However, the traffic drops off soon, and you end up running extra dynos. Reducing the upscale dyno increment and the downscale cooldown time would be beneficial.

The scale up increment is two, and the downscale cool down is one hundred and twenty seconds in this situation.

![Edit Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_7-78b9f16f783d4619b12736b925757153de31b5209148e7b3ae4644a81d0be99a.png) Navigate to Web Dyno Auto Scaling Page and edit the active rule.

![Edit Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_8-e1efe299934c0b463815fb33790176bd6f9c23cae88bc0dd6c0e0f4886a6f419.png) Reduce the upscale increment from two to one and the downscale cooldown to sixty seconds. Click Save to commit the rule and cut costs.

Optimizing for traffic demand over cost savings
-----------------------------------------------

When checking the Web Dyno Activity report, it may be obvious that heavy loads are driving your service to auto scale up, but scaling up to meet demand can take a long time. Users of your application will encounter increased queue time and a worse experience during this scaling up phase. Increasing the upscale dyno increment and reducing the upscale cooldown time would be useful.

The scale up increment is two, and the autoscale cool down is sixty seconds in this instance.

![Edit Rule](https://dynoscale.net/assets/blog/advanced_autoscaling_9-7923ff806b7354fa74f2c0b6974d2f2086a301c9254b2e071332d088db3d8b78.png) Navigate to Web Dyno Auto Scaling Page and edit the active rule.

![Edit Upscale Increment and cool down](https://dynoscale.net/assets/blog/advanced_autoscaling_10-556d24ed0bb2455b2828f788fda733d325fbe99c49bbf8290ce7b94efdf383f8.png) Increase the upscale increment from two to four and decrease the upscale cooldown to thirty seconds. Click Save to commit the rule and improve request queue time.

Conclusion
----------

The flexibility to tailor Dynoscale's Heroku autoscaling to fit your app's needs without having to write sophisticated code is one of its most powerful features. This tutorial showed you how to use Dynoscale's Heroku autoscaling in a more complex way to fulfill the performance requirements of your app. It also demonstrated how to adjust just a few configuration settings to enable the maximum capabilities of autoscaling for your app.