适用于图像重型应用程序的最佳Ruby on Rails架构 [英] Best Ruby on Rails Architecture for Image Heavy App

查看:83
本文介绍了适用于图像重型应用程序的最佳Ruby on Rails架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,该应用程序可以一次上传大量照片,并想知道解决该问题的最佳设置。

I'm building an application that allows for large amounts of photo uploads at once, and wanted to know what the best setup would be to tackle this.

此到目前为止,我正在使用的是

This is what I am using so far:


  • jQuery文件上传:允许用户拖放图像

  • CarrierWave:处理图像并使用ImageMagick调整图像大小

  • Amazon S3:CarrierWave通过Fog将图像上传到Amazon S3

  • Heroku:用于托管

  • Jquery File Upload: allows users to drag and drop images
  • CarrierWave: Processes images and resizes them with ImageMagick
  • Amazon S3: CarrierWave uploads images to Amazon S3 through Fog
  • Heroku: for hosting

我希望用户可以将大量图像拖放到页面上,然后导航到其他页面而上传是在后台进行的。我还希望图片在上传完成后出现。我不希望此过程锁定Heroku测功机,因此我可能需要将工作移至后台工作,但我不确定该如何使用。

I'd like to allow users to be able to drag and drop a large amount of images onto a page, and then navigate to other pages while the upload is going on in the background. I'd also like pictures to appear as they finish uploading. I don't want this process to lock up the Heroku dynos, so I probably need to move the work to a background job but I'm not sure what to use for my situation.

此类型应用程序的最佳设置是什么?我应该使用什么后台工作人员宝石?

What's the best setup for this type of app? What background worker gem should I use? Is Cloudinary a good idea?

推荐答案

我最近构建了一个应用程序,该应用程序在Heroku上接受大量上传。我决定构建自己的解决方案,而不是使用cloudinary或等效方法。这是我学到的一些经验教训:

I recently built an application which accepts a large number of uploads on Heroku. I decided to build my own solution instead of using cloudinary or an equivalent. Here are some lessons I learned:


  • 不要上传到heroku。您的整个网络工作者将在整个上传过程中被锁定。最多一分钟。

  • Don't upload to heroku. Your entire web worker will be locked down for the entire duration of the upload. That's up to a minute. Unacceptable.

使用JavaScript上传器(例如jquery-file-upload)直接上传到s3。刚开始时这有点复杂,但是一旦您能正常使用,那就太棒了。您可以使用 s3_direct_upload gem,也可以只阅读它们的源代码以从头开始制定自己的解决方案。该宝石基于 railscasts pro 情节,您必须付费,但来源可用

Use a javascript uploader (like jquery-file-upload) to upload directly to s3. This is a little complicated at first, but once you get it working it's fantastic. You can use the s3_direct_upload gem, or you can just read their source to make your own solution from scratch. That gem was based on a railscasts pro episode, which you have to pay for, but has source available.

上传完成后,向您的应用发出ajax请求,将新的s3网址作为远程网址。然后,载波将像在s3上一样在s3上处理图像,只需要几秒钟而不是一分钟。

When the upload finishes, make an ajax request to your application passing the new s3 url as a remote url. Carrierwave will then process the image on s3 like it was uploaded, except in only a couple seconds instead of up to a minute.

使用jquery-file-upload 客户端图像调整大小。有人会尝试上传5MB的照片,然后骗人说上传需要永远。

Use jquery-file-upload's client-side image resizing. Somebody's going to try to upload a 5MB photo and then bitch that the upload takes forever. This will make all uploads as fast as theoretically possible.

将s3配置为自动清除您的上传文件夹

不要使用thin。使用 unicorn 。几秒钟的时间太短,无法在瘦身上处理请求,但是拥有三四个工人的独角兽要宽容得多。

Don't use thin. Use unicorn. A couple seconds is too long to be processing a request on thin, but unicorn with three or four workers is much more forgiving.

请勿使用rmagick。这是用于处理复杂图像的更好的API,但会占用大量内存。改用mini_magick。

Don't use rmagick. It's a better API for complex image manipulation but uses amazing amounts of memory. Use mini_magick instead.

您会注意到,我没有为此使用后台处理程序。如果您确实很细致,则可以让接收远程URL的控制器将其工作传递给后台工作人员,如果您需要结果,则后台工作人员可以立即通过pubsub(faye或pusher,可能与令人兴奋的新同步宝石)。但这对于我的应用程序不是必需的,我宁愿将钱花在另一台Web dyno上,而不是在工人dyno上。

You'll note that I'm not using a background worker for any of this. If you're really feeling meticulous, you could have the controller that receives the remote url pass its work to a background worker, and if you need the result immediately the background worker could notify the UI by pubsub (faye or pusher, possibly with the exciting new sync gem). But this wasn't necessary for my application, and I'd rather spend my money on another web dyno than a worker dyno.

是的,如果您想让他们在整个应用程序周围点击时,您将需要在弹出窗口中上载(并使用某种pubsub解决方案),或者使用ember,boneer或angular或javascript将整个网站构建为javascript应用程序

And, yeah, if you want to let them click around your whole application while that's happening, you're going to need to either be uploading in a popup (and using some kind of pubsub solution), or building your whole site as a javascript application using ember or backbone or angular or whatever.

有问题吗?

这篇关于适用于图像重型应用程序的最佳Ruby on Rails架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆