
This add-on is operated by Rails Autoscale
Simple, reliable queue-based autoscaling for your Rails app.
Rails Autoscale
Last updated 28 August 2019
Table of Contents
Rails Autoscale is an add-on that automatically scales your Ruby on Rails web and worker dynos.
Autoscaling your application ensures that you can handle increased traffic while only paying for the dynos you need.
How is this different from Heroku’s own autoscaling?
Three significant differences:
- Queue-based autoscaling. Heroku’s autoscaling (and other autoscaling solutions) use response time to trigger scaling. If your app has consistent response times across all endpoints, this might be okay. However, it only takes a few poorly-performing endpoints to trigger an unnecessary scale event. Rails Autoscale uses request queue time to ensure dynos are only added when more capacity is needed.
- Worker dyno autoscaling. Autoscaling web dynos is great, but you’re probably also running worker dynos. If you’re running more than one, you should absolutely autoscale them. Rails Autoscale has you covered.
- Works on standard dynos. Heroku autoscaling is only provided on performance dynos. Rails Autoscale will work on both standard and performance dynos. Note that free and hobby dynos cannot be scaled to more than a single dyno.
Installation
I walk through the full installation and setup process in the 5-minute video below.
Rails Autoscale can be installed from railsautoscale.com, the Heroku Elements marketplace, or the via CLI:
A list of all plans available can be found here.
$ heroku addons:create rails-autoscale
-----> Adding RAILS_AUTOSCALE_URL to sharp-mountain-4005... done, v18 (free)
After Rails Autoscale is provisioned, a RAILS_AUTOSCALE_URL
config var is available in the app configuration. You don’t have to do anything with it. This setting is used by the rails_autoscale_agent
gem when communicating with the Rails Autoscale service.
Setup
To enable autoscaling functionality, you must install the rails_autoscale_agent
gem in your Rails application. Add this line to your application’s Gemfile and run bundle
:
gem 'rails_autoscale_agent'
This agent is extremely lightweight. How lightweight? You can see for yourself. The code is available here.
The agent is inserted into your Rack middleware stack for collection request queue times. The agent runs asynchronously and periodically reports this data to the Rails Autoscale service. It is active only when the RAILS_AUTOSCALE_URL
setting is present.
Rails Autoscale supports Rails 3.2+ and Ruby 1.9.3+.
Adjust your settings in the Rails Autoscale dashboard
After you deploy your application with the rails_autoscale_agent
gem, you’ll begin to see activity in your Rails Autoscale dashboard.
The dashboard can be accessed via the CLI:
$ heroku addons:open rails-autoscale
Opening RAILS_AUTOSCALE_URL for sharp-mountain-4005
or by visiting the Heroku Dashboard and selecting Rails Autoscale from the Add-ons menu.
Request queue time threshold
Rails Autoscale triggers scale events by monitoring the request queue time for every request. This is the time between Heroku accepting a request and your application beginning processing. Queue time will increase when your application servers are too busy to handle all incoming requests.
For a thorough explanation of queue time, read Nate Berkopec’s excellent article “Scaling Ruby Apps to 1000 Requests per Minute - A Beginner’s Guide”.
Rails Autoscale tracks the 95th percentile queue time, which for most applications will hover well below the default threshold of 100ms. A breach of this threshold will trigger an UPSCALE for your application, adding one web dyno. After 10 minutes of measurements below the downscale threshold (50ms by default), a DOWNSCALE event is triggered.
Settings page
The settings page is access via “settings” in the top navigation menu.
Rails Autoscale provides default settings that work for most apps, but some apps may need a higher or lower threshold. If your app is upscaling too much, try increasing the upscale threshold. If you’re never scaling back down even during quiet times, try increasing the downscale threshold.
If you need full control over autoscaling behavior, click “advanced options” and knock yourself out.
Enable autoscaling
Autoscaling is turned OFF by default upon installation. To enable autoscaling, just toggle the switch in the settings page and click “save”.
Worker autoscaling
As of August 2019, Rails Autoscale supports autoscaling worker dynos that are using Sidekiq. It’s as easy as autoscaling your web dynos, and the settings page will walk you through the setup. See the launch announcment for a video walkthrough.
Troubleshooting
If you’re not seeing any activity in the dashboard chart, these steps should resolve the issue:
- Ensure you’ve deployed your application with the
rails_autoscale_agent
gem installed. - Ensure your application has received requests since deploying with the agent gem.
- Allow 1-2 minutes for the data to show in the dashboard.
If you’re still not seeing activity in the dashboard, check your application logs. The rails_autoscale_agent
gem writes to your application log for each request and when it reports metrics via the Rails Autoscale API. If the gem is installed correctly, you should see logs preceeded with “[RailsAutoscale]”. Use the following command to tail Rails Autoscale logs in your app:
heroku logs --tail -a [YOUR-APP] -d web | grep RailsAutoscale
If you’ve verified the gem installation and you’re still not seeing queue time info in the dashboard, see the support section below.
Migrating between plans
Use the heroku addons:upgrade
command to migrate to a new plan.
$ heroku addons:upgrade rails-autoscale:newplan
-----> Upgrading rails-autoscale:newplan to sharp-mountain-4005... done, v18 ($49/mo)
Your plan has been updated to: rails-autoscale:newplan
Removing the add-on
Rails Autoscale can be removed via the CLI.
This will destroy all associated data and cannot be undone!
$ heroku addons:destroy rails-autoscale
-----> Removing rails-autoscale from sharp-mountain-4005... done, v20 (free)
Support
All Rails Autoscale support and runtime issues should be submitted via the Heroku Support channels. Send us your suggestions and feedback at feedback@railsautoscale.com.