New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I avoid Heroku Free Tier's 1hr "Sleep Mode"? #243

Open
ARH3 opened this Issue Jul 18, 2013 · 26 comments

Comments

Projects
None yet
@ARH3

ARH3 commented Jul 18, 2013

Hey-

Wondering if anyone has any experience hosting on heroku using just 1 dyno (free tier). It is working great for me except when using only 1 dyno it goes to sleep about an hour of "inactivity". I am curious how one goes about avoiding this. Is it as simple as setting the bot to run a command every 59 minutes, or does it require user input (ie: someone giving him a command) to avoid this sleeping issue.

Thanks!

@gizmotronic

This comment has been minimized.

Show comment
Hide comment
@gizmotronic

gizmotronic Jul 18, 2013

Collaborator

The only way to avoid the problem is to access your app from the web at least once an hour. API activity isn't enough to keep Heroku (or for that matter, OpenShift) from idling your application.

There's a listen action you can use to start listening for requests but you'd have to check the Heroku docs to see how to find the port/address to listen on.

Collaborator

gizmotronic commented Jul 18, 2013

The only way to avoid the problem is to access your app from the web at least once an hour. API activity isn't enough to keep Heroku (or for that matter, OpenShift) from idling your application.

There's a listen action you can use to start listening for requests but you'd have to check the Heroku docs to see how to find the port/address to listen on.

@MikeWills

This comment has been minimized.

Show comment
Hide comment
@MikeWills

MikeWills Jul 18, 2013

Contributor

Could the bot ping itself? Hit a "web page" every 50 minutes?

Mike Wills
mike@mikewills.me
http://mikewills.me
Ph: 507-933-0880

On Thu, Jul 18, 2013 at 12:34 PM, gizmo_tronic notifications@github.com
wrote:

The only way to avoid the problem is to access your app from the web at least once an hour. API activity isn't enough to keep Heroku (or for that matter, OpenShift) from idling your application.

There's a listen action you can use to start listening for requests but you'd have to check the Heroku docs to see how to find the port/address to listen on.

Reply to this email directly or view it on GitHub:
#243 (comment)

Contributor

MikeWills commented Jul 18, 2013

Could the bot ping itself? Hit a "web page" every 50 minutes?

Mike Wills
mike@mikewills.me
http://mikewills.me
Ph: 507-933-0880

On Thu, Jul 18, 2013 at 12:34 PM, gizmo_tronic notifications@github.com
wrote:

The only way to avoid the problem is to access your app from the web at least once an hour. API activity isn't enough to keep Heroku (or for that matter, OpenShift) from idling your application.

There's a listen action you can use to start listening for requests but you'd have to check the Heroku docs to see how to find the port/address to listen on.

Reply to this email directly or view it on GitHub:
#243 (comment)

@gizmotronic

This comment has been minimized.

Show comment
Hide comment
@gizmotronic

gizmotronic Jul 18, 2013

Collaborator

In theory, yes, but I'm sure it depends on the provider. It'd be interesting to know whether they will keep the dyno up if the access comes from the same machine.

Collaborator

gizmotronic commented Jul 18, 2013

In theory, yes, but I'm sure it depends on the provider. It'd be interesting to know whether they will keep the dyno up if the access comes from the same machine.

@ARH3

This comment has been minimized.

Show comment
Hide comment
@ARH3

ARH3 Jul 18, 2013

gizmotronic, are you saying I have to view the actual page, as opposed to interacting via a TT room?

I've designed the bot so it can talk to people in the public chat. For example, if you say "Hi Bruce", he will respond with a witty comment (for context, the bot's name is Bruce). So perhaps if ever 50 minutes I could make him say a certain command that will trigger one of his pre-defined responses.

I will probably try this approach when I get a chance to make some adjustments.

ARH3 commented Jul 18, 2013

gizmotronic, are you saying I have to view the actual page, as opposed to interacting via a TT room?

I've designed the bot so it can talk to people in the public chat. For example, if you say "Hi Bruce", he will respond with a witty comment (for context, the bot's name is Bruce). So perhaps if ever 50 minutes I could make him say a certain command that will trigger one of his pre-defined responses.

I will probably try this approach when I get a chance to make some adjustments.

@ARH3

This comment has been minimized.

Show comment
Hide comment
@ARH3

ARH3 Jul 18, 2013

Per this Stack Overflow page it appears that you can install this Heroku performance monitoring add-on to circumvent the issue.

Now, this might be a result of my limited node.js experience, so please excuse my potential ignorance, but every time I hit my app's page, my bot leaves the room and re-enters it. I think this is because it restarts the http server instance created by the node file. Is this just how node works or did I just make my bot in a really n00b way?

ARH3 commented Jul 18, 2013

Per this Stack Overflow page it appears that you can install this Heroku performance monitoring add-on to circumvent the issue.

Now, this might be a result of my limited node.js experience, so please excuse my potential ignorance, but every time I hit my app's page, my bot leaves the room and re-enters it. I think this is because it restarts the http server instance created by the node file. Is this just how node works or did I just make my bot in a really n00b way?

@Izzmo

This comment has been minimized.

Show comment
Hide comment
@Izzmo

Izzmo Jul 18, 2013

Collaborator

OpenShift's is 48 hours with inactivity. If you want, I can send a http request to your bot's webservice every 30 minutes @ARH3 from my web server if you'd like. This should keep it from going idle.

EDIT:
@MikeWills brings up a good point. You could simply send a http request to yourself and possibly circumvent the idle. Not sure if they have detection in place for this though.

Collaborator

Izzmo commented Jul 18, 2013

OpenShift's is 48 hours with inactivity. If you want, I can send a http request to your bot's webservice every 30 minutes @ARH3 from my web server if you'd like. This should keep it from going idle.

EDIT:
@MikeWills brings up a good point. You could simply send a http request to yourself and possibly circumvent the idle. Not sure if they have detection in place for this though.

@MikeWills

This comment has been minimized.

Show comment
Hide comment
@MikeWills

MikeWills Jul 18, 2013

Contributor

That would work too... a simple wget call would work.

Mike Wills
http://mikewills.me

Contributor

MikeWills commented Jul 18, 2013

That would work too... a simple wget call would work.

Mike Wills
http://mikewills.me

@ARH3

This comment has been minimized.

Show comment
Hide comment
@ARH3

ARH3 Jul 18, 2013

Thanks @MikeWills and @Izzmo I will try some of these ideas.

I still wonder though: every time I ping or wget my app, it is going to remove my bot from the room and then add him back in there. I think this is because every time the page is pinged, this code is run: var bot = new Bot(AUTH, USERID, ROOMID);

Any ideas for how to circumvent that so people in the TT room don't notice the disturbance?

ARH3 commented Jul 18, 2013

Thanks @MikeWills and @Izzmo I will try some of these ideas.

I still wonder though: every time I ping or wget my app, it is going to remove my bot from the room and then add him back in there. I think this is because every time the page is pinged, this code is run: var bot = new Bot(AUTH, USERID, ROOMID);

Any ideas for how to circumvent that so people in the TT room don't notice the disturbance?

@MikeWills

This comment has been minimized.

Show comment
Hide comment
@MikeWills

MikeWills Jul 18, 2013

Contributor

Maybe it isn't calling the same script and calling a new version?

Mike Wills
http://mikewills.me

Contributor

MikeWills commented Jul 18, 2013

Maybe it isn't calling the same script and calling a new version?

Mike Wills
http://mikewills.me

@Izzmo

This comment has been minimized.

Show comment
Hide comment
@Izzmo

Izzmo Jul 18, 2013

Collaborator

You need to add a HTTP web service to your file then @ARH3, so when someone requests the page, it will return the http response instead of reloading ur app.

Collaborator

Izzmo commented Jul 18, 2013

You need to add a HTTP web service to your file then @ARH3, so when someone requests the page, it will return the http response instead of reloading ur app.

@ARH3

This comment has been minimized.

Show comment
Hide comment
@ARH3

ARH3 Jul 18, 2013

Thanks @Izzmo that is probably it. I hacked this bot together a while back and am only now revisiting it with a renewed interest in learning more about node. I will play around with some of these suggestions and see what I can do.

Here is the main file of my bot if anyone cares to look. It is one, big, ugly file :). I am also noticing that ALL my functions and code are within the "http.createServer" function, which I'm sure is awful practice. After looking at @MikeWills's bot I think I will try to mimic what I am seeing there and see what happens.

Thanks for all the help everyone!

ARH3 commented Jul 18, 2013

Thanks @Izzmo that is probably it. I hacked this bot together a while back and am only now revisiting it with a renewed interest in learning more about node. I will play around with some of these suggestions and see what I can do.

Here is the main file of my bot if anyone cares to look. It is one, big, ugly file :). I am also noticing that ALL my functions and code are within the "http.createServer" function, which I'm sure is awful practice. After looking at @MikeWills's bot I think I will try to mimic what I am seeing there and see what happens.

Thanks for all the help everyone!

@Izzmo

This comment has been minimized.

Show comment
Hide comment
@Izzmo

Izzmo Jul 18, 2013

Collaborator

Yeah, definitely don't put it all with the createServer function =P

Collaborator

Izzmo commented Jul 18, 2013

Yeah, definitely don't put it all with the createServer function =P

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 19, 2013

wow, that is the uglest code, i have ever seen, besides the code that I wrote for my turntable.fm bot.

ghost commented Jul 19, 2013

wow, that is the uglest code, i have ever seen, besides the code that I wrote for my turntable.fm bot.

@ARH3

This comment has been minimized.

Show comment
Hide comment
@ARH3

ARH3 Jul 19, 2013

lol @Turntablelover no offense taken, that was my first foray into node EVER.

Below is the final solution that is working great for me and keeping my app from going idle. All you have to do is replace "myapp.herokuapp.com" with the subdomain for your own heroku-hosted app. Thanks for all the help everyone, and I hope others find this useful in the future! CODE:

var minutes = 20, the_interval = minutes * 60 * 1000;

setInterval(function() {
var options = {
host: 'myapp.herokuapp.com'
};
http.get(options, function (http_res) {
console.log("Sent http request to myapp.herokuapp.com to stay awake.");
});
}, the_interval);

ARH3 commented Jul 19, 2013

lol @Turntablelover no offense taken, that was my first foray into node EVER.

Below is the final solution that is working great for me and keeping my app from going idle. All you have to do is replace "myapp.herokuapp.com" with the subdomain for your own heroku-hosted app. Thanks for all the help everyone, and I hope others find this useful in the future! CODE:

var minutes = 20, the_interval = minutes * 60 * 1000;

setInterval(function() {
var options = {
host: 'myapp.herokuapp.com'
};
http.get(options, function (http_res) {
console.log("Sent http request to myapp.herokuapp.com to stay awake.");
});
}, the_interval);

@MikeWills

This comment has been minimized.

Show comment
Hide comment
@MikeWills

MikeWills Jul 19, 2013

Contributor

My first bot's code was ugly too... Then I rewrote from scratch trying to make it more organized.

This is what I was thinking. Glad to see it works.

Contributor

MikeWills commented Jul 19, 2013

My first bot's code was ugly too... Then I rewrote from scratch trying to make it more organized.

This is what I was thinking. Glad to see it works.

@samuri51

This comment has been minimized.

Show comment
Hide comment
@samuri51

samuri51 Aug 13, 2013

the thing i've found to solve this problem is to declare your process as type worker in your Procfile. the reason for this is that type web does not listen on any ports. then use bot.listen() and make sure your bot does something every once in a while. it never idles me and i didn't have to specifically send it messages or whatever, just use the api as normal

samuri51 commented Aug 13, 2013

the thing i've found to solve this problem is to declare your process as type worker in your Procfile. the reason for this is that type web does not listen on any ports. then use bot.listen() and make sure your bot does something every once in a while. it never idles me and i didn't have to specifically send it messages or whatever, just use the api as normal

@MikeWills

This comment has been minimized.

Show comment
Hide comment
@MikeWills

MikeWills Aug 14, 2013

Contributor

This information would be great to publish in the wiki so others can easily find it in the future.

Contributor

MikeWills commented Aug 14, 2013

This information would be great to publish in the wiki so others can easily find it in the future.

@gizmotronic

This comment has been minimized.

Show comment
Hide comment
@gizmotronic

gizmotronic Aug 24, 2013

Collaborator

I agree! Nice find.

One thing I've noticed with the web type specified is that even if I attempt to keep it running with a periodic request, Heroku restarts the app every 24 hours. I'm curious, have you noticed the same thing with the worker type?

Collaborator

gizmotronic commented Aug 24, 2013

I agree! Nice find.

One thing I've noticed with the web type specified is that even if I attempt to keep it running with a periodic request, Heroku restarts the app every 24 hours. I'm curious, have you noticed the same thing with the worker type?

@romainbutteaud

This comment has been minimized.

Show comment
Hide comment
@romainbutteaud

romainbutteaud Apr 17, 2014

Hi guys, I made a very simple tool that pings your Heroku app every 30 minutes so it will never fall asleep again.

romainbutteaud commented Apr 17, 2014

Hi guys, I made a very simple tool that pings your Heroku app every 30 minutes so it will never fall asleep again.

@jeffjia

This comment has been minimized.

Show comment
Hide comment
@jeffjia

jeffjia May 22, 2014

Please try CloudUp. It visits your apps periodically to keep them awake. It is free, and you can add as many apps as you want. It also activates apps on Google App Engine and Azure.

jeffjia commented May 22, 2014

Please try CloudUp. It visits your apps periodically to keep them awake. It is free, and you can add as many apps as you want. It also activates apps on Google App Engine and Azure.

@raviteja548

This comment has been minimized.

Show comment
Hide comment
@raviteja548

raviteja548 Nov 20, 2014

@romainbutteaud , After adding heroku app to your tool is there any way remove or stop pings?

raviteja548 commented Nov 20, 2014

@romainbutteaud , After adding heroku app to your tool is there any way remove or stop pings?

@chesterl

This comment has been minimized.

Show comment
Hide comment
@chesterl

chesterl Jan 4, 2015

what @raviteja548 said!
There's no option to stop it right now. And no contact info.

chesterl commented Jan 4, 2015

what @raviteja548 said!
There's no option to stop it right now. And no contact info.

@romainbutteaud

This comment has been minimized.

Show comment
Hide comment
@romainbutteaud

romainbutteaud commented Jan 4, 2015

@raviteja548 @chesterl, for now I can remove them manually.
Also, see romainbutteaud/Kaffeine#3 and romainbutteaud/Kaffeine#4

@varatep

This comment has been minimized.

Show comment
Hide comment
@varatep

varatep Jan 10, 2015

@romainbutteaud kaffeine is very impressive and does a nice job of keeping the dynos awake. Much appreciation.

varatep commented Jan 10, 2015

@romainbutteaud kaffeine is very impressive and does a nice job of keeping the dynos awake. Much appreciation.

@matijaabicic

This comment has been minimized.

Show comment
Hide comment
@matijaabicic

matijaabicic Sep 10, 2015

@romainbutteaud - Awesome little tool, kudos to you, my friend !

matijaabicic commented Sep 10, 2015

@romainbutteaud - Awesome little tool, kudos to you, my friend !

@ldco2016

This comment has been minimized.

Show comment
Hide comment
@ldco2016

ldco2016 Oct 5, 2017

Is there any use case out there where pinging our Heroku app every hour for a site that gets little traffic resulting in dyno hours being drastically diminished to the point where the developer had to stop scheduling an hourly ping?

ldco2016 commented Oct 5, 2017

Is there any use case out there where pinging our Heroku app every hour for a site that gets little traffic resulting in dyno hours being drastically diminished to the point where the developer had to stop scheduling an hourly ping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment