简体   繁体   English

如何使用Rails图像模型和attachment_fu提高性能?

[英]How to improve performance with our Rails image model and attachment_fu?

I've been trying to improve performance our app. 我一直在尝试改善我们应用的性能。 The worst performing area seems to be the creation of our Image model, which uses attachment_fu: 表现最差的方面似乎是我们的Image模型的创建,该模型使用attachment_fu:

class Image < Attachment

  ...

  has_attachment :content_type => :image,
    :max_size => 100.megabytes,
    :storage => :file_system,
    :path_prefix => 'public/uploaded/images',
    :thumbnails => { :small => '75x75>', :medium => '160x120>', :large => '600x600>' },
    :s3_access => :authenticated_read

  validates_as_attachment

  after_create :move_to_s3

  ...

We've already moved the move_to_s3 method to a delayed_job. 我们已经将move_to_s3方法移动到了delay_job中。

Our apdex score on this transaction is horrible (often < 0.5) and it's taking 1 to 2 seconds. 我们在这笔交易中的apdex分数非常糟糕(通常<0.5),需要1到2秒。

How else can I improve the creation of Image records (speed-wise)? 我还能如何改善图像记录的创建(速度方面)?

I may be able to do without the :small thumbnail? 我可以不用:small缩略图吗? Would it help to drop that? 删除它会有所帮助吗?

If it helps, most of these files are high-res images. 如果有帮助,则大多数这些文件都是高分辨率图像。 Does the upload time factor into the metrics I have? 上传时间是否影响我的指标? Is it skewing the reports? 它歪斜了报告吗?

I would save the image directly to S3 , then created a delayed job to download it, resize it, and put the thumbnails back in S3. 我将图像直接保存到S3 ,然后创建了一个延迟的作业来下载它,调整大小并将缩略图放回S3中。

To show the image on the next page load, just link to the large version and resize it via css. 要在下一页加载时显示图像,只需链接到大版本并通过CSS调整其大小即可。

Also, yes, the fewer sizes you need, the less processing it will take. 另外,是的,所需的尺寸越少,所需的处理就越少。

You could use mod_porter to let the webserver handle the upload, instead of your app. 您可以使用mod_porter来让网络服务器代替您的应用来处理上传。

This isn't going to "speed up" anything, but it will keep one of your app servers from blocking until the file is actually uploaded. 这不会“加速”任何事情,但是它将阻止您的应用服务器之一在实际上传文件之前被阻止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM