Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: I have a request that takes more than 30 seconds and it breaks

I have a request that takes more than 30 seconds and it breaks.

What is the solution for this? I am not sure if I add more dynos this will work.

Thanks

like image 691
donald Avatar asked Jun 26 '11 17:06

donald


People also ask

How do I stop Heroku request timeout?

To avoid this situation Heroku recommends setting a timeout within your application and keeping the value well under 30 seconds, such as 10 or 15 seconds.

How long is Heroku free for?

Personal accounts are given a base of 550 free dyno hours each month. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours added to the monthly free dyno quota.

How many projects can I host on Heroku for free?

A 'Free' tier Heroku account allows up to 5 apps.


1 Answers

You should probably see the Heroku devcenter article regarding this, as the information will be more helpful, here's a small summary:

To answer the timeout question:

Cedar supports long-polling and streaming responses. Your app has an initial 30 second window to respond with a single byte back to the client. After each byte sent (either recieved from the client or sent by your application) you reset a rolling 55 second window. If no data is sent during the 55 second window your connection will be terminated.

(That is, if you had Cedar instead of Aspen or Bamboo you could send a byte every thirty seconds or so just to trick the system. It might work.)

To answer your dynos question:

Additional concurrency is of no help whatsoever if you are encountering request timeouts. You can crank your dynos to the maximum and you'll still get a request timeout, since it is a single request that is failing to serve in the correct amount of time. Extra dynos increase your concurrency, not the speed of your requests.

(That is, don't bother adding more dynos.)

On request timeouts: Check your code for infinite loops, if you're doing something big:

If so, you should move this heavy lifting into a background job which can run asynchronously from your web request. See Queueing for details.

like image 137
Arka Avatar answered Sep 23 '22 06:09

Arka