limiting I/O and CPU on Linux with nice and ionice
Thursday, March 18th, 2010In one of my earlier posts about web hosting with Ubuntu Server, I left the startup script for the user-owned Apache instances as an exercise for the reader; the gist of it is to create a script in /etc/init.d/ (based on the “skeleton” file in that directory). The meat of it is something like:
do
apache2 -f /var/www/$d/conf/apache2.conf -k start
done
This iterates over the directories in /var/www and runs Apache for each one, each with it’s own config file.
One interesting thing you can do here is make the user’s Apache process “nice” to fellow processes:
do
nice -10 ionice -c3 apache2 -f /var/www/$d/conf/apache2.conf -k start
done
“nice” changes priority for tasks waiting on CPU, while “ionice” changes the priority for tasks waiting on IO (for example disk reads and writes).
This can keep one busy or misbehaving server from interrupting other sites or important background tasks; alternatively, you could set one site to be highest-priority.