This add-on is operated by Rails Autoscale
Automatic web dyno scaling designed for Rails apps
Last updated 17 October 2018
Table of Contents
Rails Autoscale is an add-on that automatically scales your Ruby on Rails web 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?
The main difference is how scaling needs are determined. Heroku’s autoscaling (and other autoscaling solutions) use response time to trigger scaling. If your app has consistent response times across all endpoints, this works great. 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.
Provisioning the add-on
Rails Autoscale can be installed via the 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. This setting is used by the
rails_autoscale_agent gem when communicating with the Rails Autoscale service.
Installing the gem
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
This automatically inserts the agent into your Rack middleware stack. The agent runs asynchronously and periodically reports request queue information 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+.
After installing the Rails Autoscale add-on and the
rails_autoscale_agent gem, your application is ready to integrate with the add-on.
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.
The thresholds typically need customizing for each application. Keep an eye on the dashboard chart to see where your queue times hover, and adjust accordingly via the “settings” panel. Note that the “upscale threshold” and “downscale threshold” indicators in the chart will move in real-time as you adjust threshold values.
Autoscaling is turned OFF by default upon installation. In the settings panel, check the “Enable autoscaling” checkbox to turn it on.
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
- 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
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)
All Rails Autoscale support and runtime issues should be submitted via the Heroku Support channels. Send us your suggestions and feedback at email@example.com.