Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase Heroku 30s h12 timeout

I'm running a rails app, which has a json webservice call from a local client developed in c++ (a post command with a multipart json form, uploading a streamed file)

I already read on Heroku docs about routing mesh, mentioning the 30s Heroku limit for http connections, and about the long polling alternative, referring to worker dynos.

During my call I process pdf documents and insert a signature into them. This pdf documents can either be 100kb or 11Mb (or perhaps more).

I understand that I'll eventually have to do this action on a background process, but I would like to avoid doing it before I absolutely have to.

Do you know of any way of increasing this timeout?

As you may see in my code below, I am processing my document after it gets saved (I was doing this inside an after_save, but changed to the controller hoping to send the response before processing).

I would so expect that the client would get a response before the document processing, but I'm still having a timeout on the heroku side, and an error on my client side.

This all works fine with smaller documents, but for a 121 pages pdf document with only 400kb, it blows off..

In the end, my file gets uploaded, so all I need is for that response to proceed to my client app before the timeout response is sent...

Any suggestions?

my error:

 at=error code=H12 desc="Request timeout" method=POST path=/documents host=fierce-beach-2720.herokuapp.com fwd="81.193.155.217/bl4-155-217.dsl.telepac.pt" dyno=web.1 queue=0ms wait=0ms connect=1ms service=32272ms status=503 bytes=0

my controller :

respond_to do |format|
      if @document.save!
        format.html { redirect_to root_path, :flash => { :success =>  'Document was successfully created.'} }
        format.json { render json: @document, status: :created, location: @document}
        @document.document_process
like image 695
MrWater Avatar asked Oct 05 '22 23:10

MrWater


2 Answers

I've ended using delayed job + workless, and now my worker dynos only run when they need to.

As heroku has the free 750 hours free per app plan, when you have low usage, you might be able to keep using it for free.

like image 150
MrWater Avatar answered Oct 13 '22 02:10

MrWater


the suggestion is: use a background process!

i read that you want to avoid it, but there is no way around it! it is a best practice in web-apps to return to the client as fast as possible, because it frees up resources. when you have just one dyno running at heroku and you have multiple requests, they will get blocked for your timeout and no user is able to access your page. you can easily have denial of service cases when you have such longrunning processes.

in case you do not want to do background processes because of the cost, have a look at freemium: https://github.com/phoet/freemium

like image 21
phoet Avatar answered Oct 13 '22 00:10

phoet