Heroku Webhook Fails Sometimes - heroku

I'm creating a chatbot with dialogflow and I have a webhook hosted on heroku (so that I can use python scripts). The webhook works fine most of the time. However when I haven't used it in a while it will always fail on the first use with a request timeout. Has anyone else come across this issue? Is there a way to wake up the webserver before running the script I have written?

Heroku's free dynos will sleep after 30 minutes of inactivity.
Preventing them from sleeping is easy. You need to use any of their paid plans.
See https://www.heroku.com/pricing
Once you use a Hobby dyno, your app will never sleep anymore and you shouldn't be getting request timeouts.
Alternatively, you can also benchmark what's taking a long time to boot your app. With a faster boot time, the first request would be slow but wouldn't get a timeout.
Heroku times out requests after 30 seconds.

Related

Heroku website only loads slowly the first time, even after clearing local cache?

I have a website hosted on heroku. Whenever I load it for the first time after awhile (I haven't figured out the exact interval yet, be it days or hours), it takes upwards of 15 seconds to load. Subsequent loads are <1second, even if I clear the cache completely and open it in an incognito tab.
Why might this be? It almost seems like some kind of DNS issue but I haven't really got a clue. I don't know how to troubleshoot something like this. The situation seems to be the same even on other computers at other locations.
Quoting the Heroku docs:
If an app has a free web dyno, and that dyno receives no web traffic in a 30-minute period, it will sleep.
When the dyno receives traffic again, it will take a few seconds to wake up, hence the delay you've experienced.
Note that the Heroku free tier also has a maximum number of dyno hours per month. A sleeping dyno doesn't use any hours, but it does when it's active. When the hours are used up, the dyno won't wake up to incoming traffic.
You can see your remaining quota of dyno hours with:
$ heroku ps -a <app name>
Heroku suggests upgrading to a hobby dyno if your app needs to be permanently accessible. More info on https://devcenter.heroku.com/articles/free-dyno-hours
On the free tier, Heroku dynos go to sleep if they aren't used after an hour or something like that. They take a few seconds to wake up. Pay for the service and it stops happening, or write a script to ping your site every couple minutes or something.

Hubot Heroku route message on startup

I have deployed a Hubot on Heroku to interact with Slack. I am using a free dyno currently. After 30 minutes of inactivity, it goes to sleep. It wakes up when pinged from Slack. However, the first request is lost in the mix. So the user has to type the command a second time. Is there an easy way to make the bot wake up and still handle the first command?
As stated in the documentation :
To get around this, you can use the hubot-heroku-keepalive script, which will keep your free dyno alive for up to 18 hours/day. If you never want Hubot to sleep, you will need to upgrade to Heroku's hobby plan.
I use it so Hubot is at least online from 6 AM to midnight.

Does Heroku change dyno IP during runtime?

I am currently working on a ruby/heroku app, that needs to query ~40 consecutive SOAP calls from a server, uploads a file to a FTP, then sleeps 15 Minutes and begins anew.
Strangely, yesterday everything worked fine (in the evening hours) either locally or via the dyno; now, since morning, I seldomly get through to the 10th query - it always stops on
D, [2014-03-20T14:18:49] Debug -- : HTTPI POST request to www.XXXX.de (net_http)
with a Connection timed out.
Locally, via foreman, everything works fine, so I'd like to rule out that the server doesn't accept 40 queries within about two minutes.
I came to the conclusion that maybe during runtime, the dyno IP is being changed; that would explain the timeout during SOAP call. Do I have to build a new savon-client for every call?
Heroku Dynos are ephemeral application instances. They may come up/down at any time and be replaced by a new one, or have your application restarted.
So, Dynos may often change which will result in new IPs for your app servers. However, the IP is very unlikely to change while the dyno is up and running. Only to be replaced by a new dyno with a different IP.

Upgrade process on Heroku?

If I update an application running on Heroku using git push and this application is running on multiple dynos - how is the upgrade process run by Heroku?
All dynos at the same time?
One after another?
...?
In other words: Will there be a down-time of my "cluster", or will there be a small time-frame where different versions of my app are running in parallel, or ...?
well can not tell the internal state but what i have experienced is
Code push complete
Code compiled (slug is compiled )
After that all dynos get the latest code and get restarted. (restart take up to 30 seconds or so and during this time all requests get queue).
So there will be no down time as during the restart process all the requests get queued and there i dont think that that multiple versions of your code will be running after the deployment.
Everyone says there's 'no downtime' when updating a Heroku app, but for your app this may not be true.
I've recently worked on a reasonably sized Rails app that takes at least 25 seconds to start, and often fails to start inside the 30 seconds that Heroku allows before returning errors to your clients.
During this entire time, your users are waiting for something to happen. 30 seconds is a long time, and they may not be patient enough to wait.
Someone once told me that if you have more than 1 dyno, that they are re-started individually to give you no downtime. This is not true - Heroku Stops all dynos and then Starts all Dynos.
At no time will there be 2 versions of your app running on Heroku

HTTP streaming on Heroku (upload lots of data)

I have one app hosted on Heroku and this app saving lots of data information to database (it takes about 70 seconds).
Heroku after 30 seconds period of every request display the error page H12 about timeout, how could I display some info-message while the upload is in progress instead of displaying H12 error?
I have been looking for some example of this, but I wasn't much successful... I just found some notes, that I have to send every time (eg. 15 seconds) some control string from server, but I already didn't find some specific example how to do that...
Any advices how to do that?
Thank in advance.
It is a poor practice to have your users wait for 70 seconds for a request to complete on any platform. Heroku just enforces this best practice by implementing the 30-second timeout. So the real question is how to better architect the application.
Heroku has an article on implementing background workers which are designed to solve this very problem: https://devcenter.heroku.com/articles/queueing
The basic approach is to have the web request schedule a background job (using Delayed Job, Queue Classic, Resque etc...) and immediately respond to the user with some indicator of progress. Then a dyno running a background worker does the heavy lifting of saving the info to the db. When it's done it flips some flag in a db or other storage mechanism which notifies to the web client that the job is now complete.
Running a background worker does require another dyno. If you're looking to avoid that expense you can look into Girl Friday which many report having success with.
Hope that helps.

Resources