Limiting Resources: nice & ionice

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, October 31, 2008

Follow me on Twitter as @mattiasgeniar

Limiting a certain process’ CPU usage can be done by changing its “nice"-value. This value determines how “nice” you are to other processes. If the value is high (10+) the process is considered very nice, because it’s not hogging up the entire CPU. It gives room for other processes too – because it’s operating more in the background.

If your nice value is below zero (-18 until 0), the process is being given priority, causing other processes to stay in queue before they can be executed.

While this is a great way of limiting certain resources, it’s only a limitation based on the CPU usage. And if you’ve ever copied large amounts of data through a USB external disk, you’ll have noticed that it’s not the CPU, but the I/O access that cause your server to respond slowly (disk read/writes).

It’s because the “cp” command used to copy data from your USB device, will have a great priority in reading/writing to and from your disk. This means that any other process that requires disk access (and that’s just about everything) is slowed down immensely.

This can be prevented by using ionice, a tool similar to nice but only for io-requests. You can reduce the stress created by the copy command, by making it run more idle – or in the background, causing other processes to access the hard disk without delay.

ionice -c3 -p

The command above will limit the process with id “” to an “idle” state, meaning it’s run more in the background and will no longer influence your other disk-access requests.

This is useful when creating back-ups or are performing other IO-heavy duties, while still guaranteeing a quick and responsive server, both for you and your (website) visitor.

More information on ionice can be found over at Fried CPU, and the Linux Man pages for ionice.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.