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 “
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.