开发者

ruby process when server is free

开发者 https://www.devze.com 2023-02-04 12:38 出处:网络
I want to run a Stalker job, only when the CPU load is less so that the site wont be affected. The job is to convert videos from any format to flv and mp4. so its a pretty expensive job.

I want to run a Stalker job, only when the CPU load is less so that the site wont be affected.

The job is to convert videos from any format to flv and mp4. so its a pretty expensive job.

how can i achieve this?

EDIT

is this a good way?

how about smthng like

load = `uptime`.gsub(/(.*): /,'').strip.split ' '
if (load[0].to_f < 0.7 && load[0].to_f < load[1].to_f) || (!args["max_delay"].nil? && total_delay > args["max_delay"] && load[0].to_f < 0.85)
  do stuff
end
开发者_运维问答


Run a separate Ruby interpreter process that does only the transcoding and run it with nice -n 19 or perhaps nice -n 12.

You may want to lower your priority (raise the nice level) within Ruby code after already starting the interpreter.

Now, you can use Process.setpriority to change the interpreter's priority. But unless you are privileged or are on Linux and have the CAP_SYS_NICE capability, you won't be able to get back to normal priority.

A strategy for that problem might involve receiving some work to do, executing Process or Kernel.fork, lowering the priority, running the job, and then calling exit.

0

精彩评论

暂无评论...
验证码 换一张
取 消