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?
Heroku now has a cron-equivalent add-on called Scheduler. Based on a tutorial:
In app/lib/tasks, add a file named
scheduler.rake
with this task defined:Add the "Scheduler" addon from your Heroku control panel or from the console:
heroku addons:add scheduler:standard
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.
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.
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.
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
It's in the FAQ, at the end, "What is dyno idling?"
https://devcenter.heroku.com/articles/dynos
Basically, this happens on the free tier. If you start up a second dyno (i.e., pay $35/month), the dynos will not idle.
If it's the case where your client is doing a presentation, i.e., a scheduled look at the application during a meeting, the idling doesn't occur until after an hour of inactivity. If he doesn't feel like paying $35/month in this scenario, he can poke the application before the meeting to wake it up.
There are two options:
Pay for it
As soon as you
heroku scale web=
above 1 the app will never iddle out, as cjk and flurdy also mention in their answer. This is by far the best option if you have a single site that is paying its own bills. If you're maintaining many sites, the costs add up though.Periodically ping the service
This option is the interesting one. For low trafic sites there is no free solution I could find. Pingdom (as mentioned by ceejayoz) is free for one site, so that would solve the problem once. If you need more sites, you can also use Iron.io to keep your heroku dynos alive. This will also quickly run out of the free tier though and then you'll be paying Iron.io.
If you are lucky enough to have a server running already, you can stick a curl to your site in the crontab. This solution scales best of course.
Have your Heroku-hosted site indexed by Google (and other major search engines).
A Heroku app I uploaded a few months ago for internal use, but which has to be accessible to clients, has somehow been found by Google and the (very small) public section of the site indexed. Nevertheless, a few months after first putting it up, Google is making about one request every 70 seconds, more than enough to keep the dyno active continuously.