ozjcpg
Last Updated: May 30, 2016
·
8.844K
· rpearce
London bridge sq

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!

Enjoy!

Say Thanks
Respond

15 Responses
Add your response

10095
B51e7cdcc7a02568f78c50c5eeee2439

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 ·
10096
Dsc 8066v square

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 ·
10101
London bridge sq

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 ·
10103
1306cb3c1c4be568ca087de48bc0d967

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

over 1 year ago ·
10111
London bridge sq

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 ·
10114
E90b0742a0a78f583355470561d63197

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

over 1 year ago ·
10116
914f05e2dee020ca927249a8dd583bf7
over 1 year ago ·
10137
Ed6327421e2a20bf53bd6a00d78be0e1

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

over 1 year ago ·
10153
375b7e3e6b2365fdd0f127f4e224f4dc

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

over 1 year ago ·
10168

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 ·
14713
Default profile 5 normal

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 ·
14714
London bridge sq

@r_radkov

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 ·
14715
Default profile 5 normal

name :
meanstackapplication
url:
http://meanstackapplication.herokuapp.com/#/
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 ·
14716
London bridge sq

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 ·
14717
Default profile 5 normal

ok ,thanks a lot

over 1 year ago ·