Last Updated: May 30, 2016
· rpearce

Keep your Heroku apps awake with KeepAwake

tl;dr => keep your apps from falling asleep with KeepAwake

The Problem

If your Heroku app doesn't get traffic which justifies you spending $0.05/hr (~$34/mo) and you run it on 1 dyno, you've probably noticed that it seems to fall asleep. If your app doesn't get traffic within ~10 minutes of its last request and you are running on 1 dyno, Heroku will expire your resource and allocate it elsewhere. The issue with this, especially if you're running anything with Ruby, is that it will take a significant amount of time to re-allocate that resource to your application and spin it back up.

One solution (with Ruby) is to create a rake task which performs an HTTP GET and then use Heroku's Scheduler Add-On to run the task every 10 minutes, preventing your app from falling asleep! Huzzah! EXCEPT...when you perform jobs with Heroku Scheduler, it spins up another dyno, thus bringing your total dyno count to 2 (aka $0.05/hr) and leaves you with a small but obnoxious bill at the end of the month.

The Solution

I created a little nodejs app called KeepAwake which performs an HTTP GET every 5 minutes on all of the domains that are saved to it, thus telling Heroku to keep those apps awake!


15 Responses
Add your response


Alternative method: Use a website status monitor, such as BinaryCanary. That way you're keeping your app awake and monitoring it's uptime.

over 1 year ago ·

The free New Relic addon has a similar option that I've used for a while now, although the setup is a bit on the cumbersome side. I think I'll have to give this a try.

over 1 year ago ·

thanks for the alternatives. behind the scenes I am currently keeping a log successful/unsuccessful requests. Given that data, what would be a useful way to display it for each URL?

over 1 year ago ·

It's really easy to do that with NewRelic. Just set up availability checking :)

over 1 year ago ·

Last I checked, New Relic was only free for a little while. Looks like that has changed, though! Regardless, this is aimed at the folks who live life on the cheap and not do extra work (aka lazy)

over 1 year ago ·

w00t w00t. I can't believe I got a @rpearce pro tip in my weekly email!

over 1 year ago ·

FYI, this is a violation of Heroku's Terms of Service.

over 1 year ago ·

Your App is not working. It's giving me a 500 Error.

over 1 year ago ·

A similar though have crossed my mind some time ago and I though to myself hey, if you are willing to have your app up all the time pay and be fair with others. Especially if you can do your own "heroku", e.g. with digitalocean. Deployment process can be alike, and the pricing is low.

over 1 year ago ·

I want to remove my url from your app ,but i can't.You must put option delete from this queue

over 1 year ago ·


I'll remove you. If I did what you suggest, anyone could remove anyone, and that's not good. What URL is it?

over 1 year ago ·

name :
thank you.
I mean that only i to have permission to make this changes like a user,which can manage my url for example.This is just like a feedback.Whatever the app is pretty cool to do this things.

over 1 year ago ·

Right. That would require user management and therefore more work on it, which I don't have time for :)

It shall be removed momentarily.

over 1 year ago ·

ok ,thanks a lot

over 1 year ago ·