How can I avoid heroku stopping my dyno?

8,752

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.

Solution 4

Using the New Relic monitoring service seems to be a good option...

How to in the following post:

Avoid Heroku idling with New Relic pings

Share:
8,752
iwein
Author by

iwein

Updated on September 18, 2022

Comments

  • iwein
    iwein almost 2 years

    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?

    • Admin
      Admin over 11 years
      @ceejayoz ah, I must have missed that on their site they say 1 site 20 sms's is free... which is well, nice and all, but it's "free level of service" for varying values of free I guess. I'm not one to flame a freebee, but it's no more than that.
    • Admin
      Admin over 11 years
      Based on your question, you only need the one site, and you don't really need the SMSes at all.
    • Admin
      Admin over 11 years
      @ceejayoz, you're right, but I thought I could make your answer more complete by mentioning other options than Pingdom. Nothing against the solution, but for my particular use case (which wasn't very clear in the question) it doesn't fly. I tried to reconstruct my edit (minus the error) and put it in my own answer. You can comment there or suggest edits if you still see a problem with the wording.
  • iwein
    iwein over 11 years
    That's strange, but it is a solution if you're that lucky :)