a.barbieri
a.barbieri

Reputation: 2596

Google Cloud Storage requests are slow using Paperclip and Rails

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.

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?

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

enter image description here

Upvotes: 3

Views: 576

Answers (2)

a.barbieri
a.barbieri

Reputation: 2596

I cannot say that this sorted everything out, but at least it speeds it up.

fog_host seems to avoid the network request.

# config/application.rb
module Parasite
  class Application < Rails::Application

    config.paperclip_defaults = {
      fog_host: 'http://mybucektname.storage.googleapis.com',
      # ... other options
    }

  end
end

If you want to dig more check the code or this thread I opened on the Paperclip Github Page.

Upvotes: 0

matias elgart
matias elgart

Reputation: 1181

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.

Upvotes: 1

Related Questions