LoginSignup
2
2

More than 5 years have passed since last update.

[Rails]whenever上でrakeタスク実行の優先順位(ナイス値)を指定する

Posted at

Microsoft Azure VM A0 Basic(0.25コア、RAM0.75GB)インスタンス上で、Rails/rakeの重いバッチ処理を動かそうとしたらマシンが応答しなくなってしまいました。

niceを使ってバッチ処理の優先順位を下げてみることにしました。

環境

$ cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
$ nice --version
nice (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
ライセンス GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

作者 David MacKenzie。
$ bundle list | egrep " (rails|whenever) \("
  * rails (4.2.1)
  * whenever (0.9.4)

job_typeを自前で実装する。

javan/whenever: Cron jobs in Ruby によると、wheneverでは以下4つのjob_typeがデフォルトで設定されています。

job_type :command, ":task :output"
job_type :rake,    "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
job_type :runner,  "cd :path && bin/rails runner -e :environment ':task' :output"
job_type :script,  "cd :path && :environment_variable=:environment bundle exec script/:task :output"

これにnice値19を指定したバージョンを作成し、利用します

config/schedule.rb
job_type :nice_rake, "cd :path && :environment_variable=:environment nice -19 bundle exec rake :task --silent :output"

every '*/20 * * * *' do
  nice_rake "hoge:fuga"
end

Nice rake.

参考

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