LoginSignup
2
2

More than 5 years have passed since last update.

paperclipから呼び出すコマンドの負荷を少しでも下げたい

Last updated at Posted at 2014-12-19

運用をしていてpaperclipから呼び出すimagemagickのコマンドの負荷を少しでも下げたい場合がある
paperclipのこのメソッドからコマンド実行するときにioniceとniceを付ける

helpers.rbのrunメソッドをoverrideする

  • 開発環境がmacの場合ioniceを入れるのが面倒そうだったのでproductionのみ付けるようにした
  • 優先度は最低(ionice -c3 -n7 nice -n19)にした
config/initializers/paperclip_helpers.rbにoverrideを記述する
require 'paperclip/helpers'
Paperclip::Helpers.module_eval do
  def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
    command_path = options[:command_path]
    Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
    if logging? && (options[:log_command] || local_options[:log_command])
      local_options = local_options.merge(:logger => logger)
    end
    Cocaine::CommandLine.new("#{Rails.env.production? ? 'ionice -c3 -n7 ' : ''}nice -n19 #{cmd}", arguments, local_options).run(interpolation_values)
  end
end
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2