3

To be a bit more concrete:

I have a Debian Squeeze Linux machine with a web application that should become available all over the planet. Until now I had a bunch of resource consuming cronjobs each night (in Europe) without much impact on regional user experience. However now I cannot afford that the server gets slower at any time.

Is there a way to force all cron scripts (cron.daily etc.) to inherit a nice and ionice priority?

Thanks for contributing!

Miguel

Miguel ZP
  • 31
  • 1
  • 2

3 Answers3

2

Yes...

You could have the scripts source a particular set of environment variables or just run nice/ionice from within the script...

However, this is not a good resolution to your problem.

  • Can you offset or stagger the scripts so that they're not contending for resources?
  • Do you understand the timing or system activity patterns? E.g. Between 02:00 and 04:00, there are very few users on the system, and it's a good time to run maintenance scripts.
  • Do you have enough resources on your server?
  • nice and ionice aren't good long-term solutions. ionice, in fact doesn't have an effect on some of the more performance-based Linux kernel scheduling algorithms. It works with the CFQ scheduler, but chances are that you want to use the deadline scheduler on a server system. That may have a bigger impact than trying to force nice/ionice on the processes.
ewwhite
  • 194,921
  • 91
  • 434
  • 799
2

You may want to setting the crond service to run with nice and ionice already set.

http://b.zekjur.net/2012/09/23/systemd-ionice.html

However, I haven't tested that one, so I can't vouch for it one way or another.

If that doesn't work, or if it doesn't help enough, you'll need to configure cgroups.

Greg Bray
  • 5,530
  • 5
  • 33
  • 52
TechnoJoe
  • 21
  • 1
0

You would probably best have these cron jobs run under a separate Linux user, which you can limit to lower priority. Let's say you have such a user batchuser. In your /etc/security/limits.conf, you would want to add an entry for this user (-19 to 19, with 19 being the lowest priority):

batchuser    -       priority        19

Then any processes started by this user, whether from cron or not, will inherit this priority. No modification to scripts, no env or profiles to set.

http://manpages.debian.org/cgi-bin/man.cgi?query=limits.conf

Joshua Huber
  • 807
  • 5
  • 7