Turntable-API
Turntable-API copied to clipboard
How do I avoid Heroku Free Tier's 1hr "Sleep Mode"?
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!
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.
Could the bot ping itself? Hit a "web page" every 50 minutes? — Mike Wills [email protected] http://mikewills.me Ph: 507-933-0880
On Thu, Jul 18, 2013 at 12:34 PM, gizmo_tronic [email protected] 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: https://github.com/alaingilbert/Turntable-API/issues/243#issuecomment-21200345
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.
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.
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?
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.
That would work too... a simple wget call would work.
Mike Wills http://mikewills.me
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?
Maybe it isn't calling the same script and calling a new version?
Mike Wills http://mikewills.me
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.
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!
Yeah, definitely don't put it all with the createServer function =P
wow, that is the uglest code, i have ever seen, besides the code that I wrote for my turntable.fm bot.
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);
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.
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
This information would be great to publish in the wiki so others can easily find it in the future.
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?
Hi guys, I made a very simple tool that pings your Heroku app every 30 minutes so it will never fall asleep again.
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.
@romainbutteaud , After adding heroku app to your tool is there any way remove or stop pings?
what @raviteja548 said! There's no option to stop it right now. And no contact info.
@raviteja548 @chesterl, for now I can remove them manually. Also, see https://github.com/romainbutteaud/Kaffeine/issues/3 and https://github.com/romainbutteaud/Kaffeine/issues/4
@romainbutteaud kaffeine is very impressive and does a nice job of keeping the dynos awake. Much appreciation.
@romainbutteaud - Awesome little tool, kudos to you, my friend !
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?