将图像上传到AWS花费的时间异常长

时间:2018-07-15 08:50:34

标签: ruby amazon-web-services ruby-on-rails-5

环境

·红宝石(2.3.3)

·Ruby on Rails(5.1.4)

·AWS Linux

·独角兽

·Nginx

·MySQL

图书馆

·ImageMagick(带有yum的6.9.10-6 Q16 x86_64)

  • OpenMP已禁用
  • 导出MAGICK_THREAD_LIMIT =已添加“ 1”
  • 已添加导出OMP_NUM_THREADS =“ 1”

·CarrierWave(最新)

  • 已调整大小且已验证
  • 也要慢至s3(使用雾化器)

·Rmagick(最新)

相关代码

应用程序/上传器/ thumbnail_uploader.rb

class ThumbnailUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  process :fix_exif_rotation
  process resize_to_fit: [400, 400]


  def fix_exif_rotation
    manipulate! do |img|
  img.auto_orient!
  img = yield(img) if block_given?
  img
    end
  end

  def filename
    super.chomp(File.extname(super)) + '.jpg' if original_filename.present?
  end

   def filename
    "#{secure_token}.#{file.extension}" if original_filename.present?
  end

  def secure_token
    media_original_filenames_var = :"@#{mounted_as}_original_filenames"

    unless model.instance_variable_get(media_original_filenames_var)
      model.instance_variable_set(media_original_filenames_var, {})
    end

    unless     model.instance_variable_get(media_original_filenames_var).map{|k,v| k }.include? original_filename.to_sym
      new_value =     model.instance_variable_get(media_original_filenames_var).merge({"#{original_filename}": SecureRandom.uuid})
      model.instance_variable_set(media_original_filenames_var, new_value)
    end

    model.instance_variable_get(media_original_filenames_var)[original_filename.to_sym]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

上传图像大约需要15秒。

请告诉我哪些文件与原因有关。 谢谢!

0 个答案:

没有答案