Limiting the CPU and Priority of a job

Post date: Nov 06, 2014 2:24:3 AM

On an active database, you're often running larger tasks that can impact the performance of the database, which is bad for a fast database-backed Web site. For example, pg_dump to make backups, COPY/CREATE INDEX as in the above examples, etc. Not to fear; there are some simple things you can do to lessen the impact, e.g.:

nice -n 20 ionice -n 4 pg_dump

nice -n 20 ionice -n 4 psql

http://en.wikipedia.org/wiki/Nice_(Unix)

http://www.tutorialspoint.com/unix_commands/ionice.htm

This wraps the command to have the lowest cpu priority (via nice) and ip priority (viaionice). Additionally I will often also use

cpulimit -e pg_dump -l 20 -z

which will limit pg_dump (in this case) to 10% of CPU while the current one ie running and then exit (via cpulimit). Of course, it also usually makes sense to run these things at off times using cron, etc.