Search code examples
ruby-on-rails-3herokuamazon-s3carrierwavefog

Heroku taking too much time to upload to S3 (carrierwave and fog)


I have a Rails app, when the user calls one action from the web the heroku app generates a random image, upload that image to S3 and the returns to the user the public url of that image (stored in s3)...

The "upload that image to S3" takes literately ages, it takes for a file of 27kb 20 seconds, that's not possible... I really don't know how to fix this, because the thing is working, it's uploading to s3 but taking way too much...

I was thinking in just storing the image in the tmp folder from the rails app but I don't know how long is going to be there before being deleted... Any idea?

thanks!


Solution

  • If the images are not temporary you should not store them on Heroku as they will be deleted when the dyno goes inactive.

    I think you should investigate moving the upload to s3 to a async background job. There are several available options: DelayedJob, Resque, and Sidekiq are some of the more popular gems for background processing. You will also have to add a worker on Heroku that will process your background jobs.

    By moving the upload to a background job your users will not have the huge wait time as the image upload process will be done separately.