How can I avoid heroku stopping my dyno?

I build MVP's for clients regularly. Often I deploy on Heroku so they can see if the product works and demo it to prospects and investors.

Then I have an application deployed on heroku, and it works like a charm, if not for one little thing. The app takes about 30 seconds to start up and heroku has the annoying habit of killing dyno's if they don't get traffic. My client is using the application for demo purposes now, so the load is extremely low and intermittent.

I'm looking for a solution that is preferably:

  • cost effective
  • can be applied to multiple apps simultaneously

What is the best way to avoid having the first request taking 30 seconds?


Solution 1:

Heroku now has a cron-equivalent add-on called Scheduler. Based on a tutorial:

  1. In app/lib/tasks, add a file named scheduler.rake with this task defined:

    desc "This task is called by the Heroku cron add-on"
    task :call_page => :environment do
       uri = URI.parse('http://www.myapp.org/')
       Net::HTTP.get(uri)
    end
    
  2. Add the "Scheduler" addon from your Heroku control panel or from the console:

    heroku addons:add scheduler:standard

  3. Configure Scheduler to run this task hourly.

    heroku addons:open scheduler

I suspect this is Heroku's preferred method, as a Heroku community rep demonstrated this technique at a talk.

Solution 2:

Simple answer: You pay for it.

Ramp up to two dynos and your app will not idle.

If cost conscious then only ramp up to two web dynos for short periods of time around your client's demos. Heroku only charge $0.05 per hour.

Or drive frequent traffic to the app somehow so it does not idle. But Heroku offer such a great service that you use for free so why not throw them a few cents for the periods you need guaranteed response.

Solution 3:

You can point a Pingdom check at your site's URL. As a bonus, you'll be keeping an eye on downtime while you do so.