Getting Timeout::Error exception in a heroku worker - heroku

I know heroku has a 30 seconds timeout limit for the dynos. But for workers, I've been executing many tasks in the past for many minutes and I had no problem. Now in a new feature of an application, I'm seeing the process in the worker is removed (Delayed Job) with a raised Timeout::Error exception if the task takes longer than 30 seconds.
I want to confirm the maximum execution time for a worker in heroku.
Thanks

There is no request timeout for workers (or dynos for that matter). Request timeouts for the users are handled by the Routing mesh.

Related

Gracefully scale down heroku web dynos

Heroku has great utilities to manage web dynos. When we do a small release we use Preboot to gracefully switch over web dynos over to the new release.
However, if you want to scale down your web dynos, there is no graceful way to do so. Ideally we can mark a web dyno so that Heroku Scheduler would stop giving it new requests for 3 minutes before sending SIGTERM.
So if i have 6 dynos running, but outside of office hours I want to ps:scale web=2, it sends SIGTERM to the other 4. If there was a straggler in slow times routed to one of those 4 (instead of the remaining 2), they'd experience a crash resulting from SIGTERM.
Is there a way to gracefully scale down web dynos?
Correctly handling SIGTERM is the recommended approach for graceful shutdown, see https://devcenter.heroku.com/articles/dynos#graceful-shutdown-with-sigterm. Please note, this the same shutdown process that occurs during preboot too. So when your process receives a SIGTERM, it should stop responding to requests, and finish responding to its current requests, after 30 seconds, if the process hasn't exited, then the process is forcefully SIGKILL'd. There is no builtin way to perform rolling scaledown, you'd have to write your own interface on the Heroku API to achieve this.

Heroku Webhook Fails Sometimes

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.

Dyno hours of crashed workers and idle web applications

'1. I currently have 1 worker dyno doing background work. I does so every day for about an hour. The rest of the time the worker dyno recognizes, that it has nothing to do and terminates. The dyno manager will respawn the dyno and after a few seconds the dyno will terminate.
It is not clear to me how this will count in computing hours, esepecially as
https://dashboard.heroku.com/account
Shows "Not available" in the current usage statistics.
The Scheduler addon doesn't seem to be the right tool for me, as they are meant for to schedule short running background tasks (according to the description)
Q1: How does a crashed worker process consume dyno hours?
'2. How is my web app being charged when idle? The documentation says "A web dyno that is idled continues to accrue usage. To stop accruing usage, you must scale the web dyno to 0". This means that an idle web app is using the same dyno hours or at a reduced rate? "continues to accrue usage" would suggest some lower rate but isn't clear out of context.
Q2: To what rate does an idling web worker consume dyno hours?
For my understanding: Heroku does not differentiate between the Dyno types when it comes to pricing. An idled Dyno will produce the same cost like a running Dyno. But Heroku says on their website: "... Workers dynos are never idled out."
A crashed Dyno will constantly try to restart with a 10 minute break (after restart fails twice in a row).

Heroku Dyno... Running Schedule tasks without a Worker

I have recently added "Heroku Scheduler" addon to my heroku app...
I currently have a free heroku account and have the standard one web dyno....
Now I have set up a scheduled comment to run with scheduler... What will happen if I keep having 0 Worker dynos....
Do I get charged?
Does my task just not run?
Or does it fall back to the web dyno and gets queued on that one?
Your scheduled task with scheduler will run when you tell it to. It is similar to a worker process, however it runs then stops running once its finish instead of continually being billed. You are billed for the time it runs, but only that time. If your task is a short task running for 1 minute, on an hourly basis then you'd be billed at 24 minutes a day.
Just as an update to my previous comment, all the above as been obviated by the recent dyno and billing changes on heroku. You can now have a free web+workder dyno, provided it sleeps for at least 6 hours per day. There are also other changes making it cheaper to run a small hobby type project, even 24 hours per day.
https://devcenter.heroku.com/articles/usage-and-billing
As Craig mentioned, the scheduler addon will run a task for a set amount of time. It will use the time from your web dyno and it will not spawn a new dyno to complete the task. As a result, your web traffic will be queued during that duration (this is my current understanding of using the scheduler addon for 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