使用回形针和Rails的Google Cloud Storage请求很慢 [英] Google Cloud Storage requests are slow using Paperclip and Rails

查看:90
本文介绍了使用回形针和Rails的Google Cloud Storage请求很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Google Cloud Storage获取图像的Rails应用程序.每个视图都有大约8张图像,并且当用户尝试加载页面时,由于对GCS的请求,需要5秒钟以上的时间才能完成.

I have a Rails application that uses Google Cloud Storage for images. Each view has approximately 8 image and when a user tries to load the page it takes more than 5 seconds to complete because of requests to GCS.

Paperclip通过以下配置发出请求:

Requests are made by Paperclip with the following config:

config.paperclip_defaults = {
  storage: :fog,
  fog_credentials: {
    google_storage_access_key_id: myAccessKey,
    google_storage_secret_access_key: mySecretKey,
    provider: 'Google'
  },
  fog_public: true,
  fog_directory: 'mybucket'
}

在我看来,我这样称呼每张图片:

In my view I call each image this way:

<%= image_tag myAsset.image.url %>

有没有更快的方法来达到相同的结果?

Is there any faster way to achieve the same result?

在我看来,延迟加载似乎是一种解决方法,而不是解决方案,我错了吗?

Lazy load seems to me a workaround rather then a solution, I'm I wrong?

这里有新的Relic臭名昭著的分析(绿色属于Google Cloud Storage请求)

Here New Relic infamous analysis (green belongs Google Cloud Storage requests)

推荐答案

给定请求的图像是否每次都从后端提取?如果是这样,请为图像使用缓存,这样您就只花时间在第一个请求上了.可能在用户身份验证后甚至开始将图像拉入缓存中-像您建议的那样延迟加载.

are the images for a given request pulled every time from the backend? if so, use a cache for the images so you only take the time hit on the first request. possibly even start pulling images into a cache after user auth's in -- lazy loading like you suggested.

这篇关于使用回形针和Rails的Google Cloud Storage请求很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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