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

发布于 2024-08-10 03:19:01 字数 729 浏览 7 评论 0原文

我一直在努力提高我们的应用程序的性能。表现最差的区域似乎是我们的图像模型的创建,它使用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

  ...

我们已经将move_to_s3方法移至delayed_job。

我们在该交易上的 apdex 得分非常糟糕(通常 < 0.5),并且需要 1 到 2 秒。

我还能如何改进图像记录的创建(速度方面)?

我可以不用:小缩略图吗?放弃它会有帮助吗?

如果有帮助的话,这些文件大多数都是高分辨率图像。上传时间会影响我的指标吗?是否歪曲了报道?

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:

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.

Our apdex score on this transaction is horrible (often < 0.5) and it's taking 1 to 2 seconds.

How else can I improve the creation of Image records (speed-wise)?

I may be able to do without the :small thumbnail? 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦魇绽荼蘼 2024-08-17 03:19:01

我会将图像直接保存到 S3,然后创建一个延迟作业来下载它,调整它的大小,然后将缩略图放回 S3 中。

要在下一页加载时显示图像,只需链接到大版本并通过 css 调整其大小即可。

另外,是的,您需要的尺寸越少,所需的处理就越少。

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.

To show the image on the next page load, just link to the large version and resize it via css.

Also, yes, the fewer sizes you need, the less processing it will take.

心的位置 2024-08-17 03:19:01

您可以使用 mod_porter 让网络服务器而不是您的应用程序处理上传。

这不会“加速”任何东西,但它会阻止您的应用程序服务器之一阻塞,直到文件实际上传。

You could use mod_porter to let the webserver handle the upload, instead of your app.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文