Linux – Is it possible to assign a nice and ionice priority to all scripts executed by cron daemon

crondebian-squeezeionicelinuxnice

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

Best Answer

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.