6

I'm using unicorn on Heroku. one of the issues I'm having is with file uploads. We use carrierwave for uploads, and basically, even for a file that's about 2MB size, by the time 50-60% upload is done, Unicorn times out.

We aren't using unicorn when we test locally, and I don't have any issues with large files locally (though the files get uploaded to AWS using carrierwave, just as with production + staging). However, on staging & production servers, I see that we get a timeout.

Any strategies on fixing this issue? I'm not sure I can put this file upload on a delayed job (because I need to confirm to my users that the file has indeed been successfully uploaded).

Thanks! Ringo

Ringo Blancke
  • 2,444
  • 6
  • 30
  • 54

2 Answers2

2

If you're uploading big files to S3 via Heroku, you can't reasonably avoid timeouts. If someone decides to upload a large file, it's going to time out. If it takes longer than 30s to upload to Heroku, transfer to S3, and process, the request will time out. For good reason too, a 30s request is just crappy performance.

This blog post (and github repo) is very helpful: http://pjambet.github.io/blog/direct-upload-to-s3/

With it, you should be able to get direct-to-s3 file uploads working. You completely avoid hitting Heroku for the bulk of the upload. Using jquery-fileupload's callbacks, you can post to your application after the file is successfully uploaded, and process it in the background using delayed_job. Confirming to your users that the upload is successful is an application problem you just need to take care of.

Nick Veys
  • 23,458
  • 4
  • 47
  • 64
0

Sounds like your timeout is set too low. What does your unicorn config look like?

See https://devcenter.heroku.com/articles/rails-unicorn for a good starting point.

Helios de Guerra
  • 3,445
  • 18
  • 23
  • 1
    my unicorn timeout was 15, upped to 30, but no difference. I would prefer to engineer a solution that doesn't depend on increasing timeout. – Ringo Blancke Sep 26 '13 at 20:21