0

We're using the autoscaler on Heroku. Almost all the requests are very quick (0-500ms), but periodically we have an image upload that takes a long time (3000-9000ms). Autoscaling doesn't help at all in this case. Is there a best practice handle this? For instance, is there a way to omit a particular URL from the autoscaler? Or do you handle this by setting up a parallel app just to handle these transactions?

Here is an example "slow" transaction (with identifiers anonymized) -- all times are intact:

May 22 11:46:19 production heroku/router: at=info method=POST path="/api/users/cases/24070/case_posts.json" host=www.website.com request_id=XXX...XXX fwd="xxx.xxx.xxx.xxx" dyno=web.1 connect=0ms service=10483ms status=200 bytes=1762 protocol=https
Started POST "/api/users/cases/24070/case_posts.json" for xxx.xxx.xxx.xxx at 2018-05-22 18:46:10 +0000
Processing by Users::CasePostsController#create as JSON
  Parameters: {
    "image"=>#<ActionDispatch::Http::UploadedFile:0x00007f3068cb98d8 @tempfile=#<Tempfile:/tmp/RackMultipart20180522-11-1x9ayll.JPG>,
    @original_filename="IMG_1325.JPG",
    @content_type="image/jpeg",
    @headers="Content-Disposition: form-data; name=\"image\"; filename=\"IMG_1325.JPG\"\r\nContent-Type: image/jpeg\r\n">,
    "step"=>"pack out",
    ...
  }
  Rendered users/case_posts/_case_post.json.jbuilder (1.0ms)
  Rendering users/case_posts/show.json.jbuilder
  Rendered users/case_posts/_case_post.json.jbuilder (0.4ms)
  Rendered users/case_posts/show.json.jbuilder (1.0ms)
Completed 200 OK in 9120ms (Views: 1.8ms | ActiveRecord: 29.8ms)
Joseph
  • 1,354
  • 12
  • 15
  • Why are some of your requests taking an order of magnitude longer? – Brian May 22 '18 at 19:32
  • We allow users to upload large audio and video files, which takes a while to do. We don't do conversions on the foreground thread though -that is deferred to a worker thread, which is not part of the autoscaling group. – Joseph May 22 '18 at 21:02
  • FYI, I've added an example "slow" transaction above. – Joseph May 22 '18 at 21:08
  • 2
    I've gotten around this on Heroku by uploading directly to S3 from the browser. – Msencenb May 22 '18 at 21:56
  • @Msencenb 's answer is probably the best idea. In our projects (albeit Django, but same idea), file uploads are always made from the frontend/browser directly to S3. Heroku only takes part in signing the URLs for the upload and subsequent download to display the uploaded file. This also bypasses Heroku's 30s timeout issue, for files that are way too large or connections that are too slow. – Luca Bezerra Jun 27 '18 at 17:04

0 Answers0