Heroku is a great tool for hosting web applications. At Breakwater, we build web and mobile apps using tools like Ruby on Rails. Heroku is a fantastic place for hosting Ruby on Rails applications or the infrastructure (like APIs) for mobile apps. Heroku is fast and easy to deploy to and takes the stress and effort out of making sure the hosting platform is secure and redundant. It makes DevOps work easy, which allows software developers to focus on what they love most–building great applications.
One of the primary complaints with Heroku is that it can become expensive as the hosting horsepower needs increase. Of course, we can build a less expensive hosting infrastructure directly on a cloud hosting platform like Amazon Web Services (AWS), but building directly on top of AWS means that we are now in charge of security updates, backups, and other DevOps tasks. How can we have our cake and eat it too?
Only use what you need
Heroku charges for most of its services by the minute. At Foraker Labs, we often have client products that don’t need peak resources all day long. For example, a typical custom business system is used primarily during the 9-5 normal workday. Ah hah! How about we only use the increased resources when we have those peak demands. There are services on Heroku that do this but I have found two problems:
They don’t seem to work very well
They cost money which defeats, to some degree, the benefits of scaling in the first place
Being a control freak
Naturally, as someone who likes to be in control and also likes to build things, I figured we could just build our own. Heroku has a great platform API and a convenient Ruby gem to easily access that API.
Enter Heroku Scaler
We have created the Heroku Scaler to give you control of scaling Heroku web dynos. Using the free Heroku Scheduler you can set up Rake tasks to scale your web dynos up and down at specific times. For example, you might:
Scale your application to 3 performance dynos at 8am each day
Scale your application down to 1 Standard-1X dyno at 6pm each day
This would allow your daytime users to enjoy increased performance but only pay for those resources during 10 hours of the day instead of all 24 hours.
How to use Heroku Scaler
The git repository has more detailed instructions for installing and using the Heroku Scaler but the basic idea is:
Add the heroku-scaler gem to your Rails project
Generate a Heroku API key
Set the Heroku configuration options
Install and configure the Heroku Scheduler
Want to contribute?
Breakwater loves open source. If you do too and want to make the Heroku Scaler better, please fork the git repository and submit a pull request.