The image upload to AWS takes an abnormally long time

Environment

· Ruby (2.3.3)

· Ruby on Rails (5.1.4)

· AWS Linux

· Unicorn

· Nginx

· MySQL

Library

· ImageMagick (6.9.10-6 Q16 x86_64 with yum)

  • OpenMP disabled
  • export MAGICK_THREAD_LIMIT = "1" Added
  • export OMP_NUM_THREADS = "1" Added

· CarrierWave (latest)

  • Resized verified
  • Slow to s3 as well (use fog-aws)

· Rmagick (latest)

Related code

app / uploaders / 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

It takes about 15 seconds to upload images.

Please tell me which files are related to cause. Thank you!