11

I have an rsync cron job which is pushing the server load and triggering monitor alerts. If I set the job to be run with a high nice level, would that effectively reduce the impact it has on system load values?

  • For rsync, it would be more effective to use its switches to either reduce compression, or limit bandwidth usage. – Nemo Jan 4 '17 at 21:16
9

It will not reduce your load.

It will only let other processes use CPU time more often if there is a possible resource contention (several processes "competing" for not enough available CPU time).

9

Changing the nice value will not directly reduce system load. It can however be used to leave more resources available to the remaining processes, which I suspect is what you really want.

From http://linux.101hacks.com/monitoring-performance/hack-100-nice-command-examples/

Kernel decides how much processor time is required for a process based on the nice value. Possible nice value range is: -20 to 20. A process that has a nice value of -20 is very high priority. The process that has a nice value of 20 is very low priority.

So yes, you want to run the cron job at a higher level than the other processes if you want to make sure that other processes get priority.

To do this you want your cron script to be executed like this:

/bin/nice -n 10 /path/to/cron-script

This will run the cron script at at niceness increased by 10. You probably want to test a bit to find a nice (pun not intended) balance between the remaining processes and the execution time of the script.

See also How is nice working? and http://www.cyberciti.biz/faq/change-the-nice-value-of-a-process/ for more details.

5

Changing the nice level of a process is unlikely to affect the system load value. The system load value is the average length of the run queue, which is basically the number of processes wanting to use the CPU.

If you are running a CPU-bound process (rsync isn't, but just for example), then it will always want to use CPU time whenever there is some available. Since it always wants to run, it will contribute a load value of 1.0 to the system load value. It doesn't matter what the process nice level is, because the average length of the run queue is unaffected by the order of processes in the run queue.

  • This is important to remember. If you run a lot of niced processes, the system load will look very high even if in fact no real work is getting slowed down. In some cases load reveals a real problem i.e. that Linux is not able to let the niced process use all the resources they could actually use without problem (all of them are left waiting most of the time for no gain). – Nemo Jan 4 '17 at 21:18
2

You might consider 3 ways to reduce your proces impact on system load/CPU time:

  • Use the nice command to manually lower the task's priority.
  • Use the cpulimit command to repeatedly pause the process so that it doesn’t exceed a certain limit.
  • Use Linux’s built-in control groups, a mechanism which tells the scheduler to limit the amount of resources available to the process.

Resources

http://blog.scoutapp.com/articles/2014/11/04/restricting-process-cpu-usage-using-nice-cpulimit-and-cgroups

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.