12 August 2010

Stop hard disk heavy processes from slowing down the entire machine on Ubuntu

So this is the deal:
We have a machine with many users and some of them are occasionally running hdd-intensive applications. This is an expected activity of the users, BUT it practically prevents other users from doing anything with the machine until the processes with the intensive hdd activities terminate.

This is why I added a "daemon" that runs in the background and checks for any hdd-intensive processes.
If any processes of this type are found, using "ionice", their I/O priority is reduced to "C 3" (idle):
from "man ionice"
"""
Idle. A program running with idle io priority will only get disk time when no other program has asked for disk io for a defined grace period. The impact of idle io processes on normal system activity should be zero. This scheduling class does not take a priority argument.
"""

The tools used here should be already there in Ubuntu. If they are not (or you just want to make sure that they are installed) you can run:
sudo apt-get install iotop util-linux grep mawk findutils

An entire "daemon" consists of adding the following line to "/etc/rc.local", just before "exit 0"

iotop -b -o -d 15 | grep "%" | grep "M/s" | awk '{print $1}' | xargs ionice -c 3 -p
Or you could run almost the same line as an ordinary user and "sudo":
iotop -b -o -d 15 | grep "%" | grep "M/s" | awk '{print $1}' | xargs sudo ionice -c 3 -p
The machine (and its users) are much happier now. :)

Hope this helps somebody else as well.

No comments: