1

I have the following command (simplified):

mysqldump <databases> | bzip2 > backupfile.sql.bz2

For some reason the bzip2 process went crazy and took the CPU load up to 60. I don't know why, but I am hoping that using nice might mitigate it in the future, but I only want nice on bzip2, not mysqldump.

Can I just change it to

mysqldump <databases> | nice bzip2 > backupfile.sql.bz2

or do I have to do

nice mysqldump <databases> | bzip2 > backupfile.sql.bz2

Thanks

2 Answers 2

2

TL;DR: The correct command is

mysqldump <databases> | nice bzip2 > backupfile.sql.bz2

The nice command only alters the niceness of the command it receives as direct argument. It does not apply to the whole pipeline or a chain of commands if you just write it at the beginning of the line.

Therefore:

  • mysqldump <databases> | nice bzip2 > backupfile.sql.bz2
    

    will do what you want and launch mysqldump normally, whereas bzip2 runs with an elevated niceness property of +10.

  • nice mysqldump <databases> | bzip2 > backupfile.sql.bz2
    

    will do the opposite of what you want, it will make mysqldump nice, but let bzip2 run normally.

  • A third option that allows you to run all commands of the pipeline nicely would be to execute them in a new shell process with elevated niceness, like

    nice bash -c 'mysqldump <databases> | bzip2 > backupfile.sql.bz2'
    

However, please note that raising a process' niceness does not necessarily reduce its CPU usage. As long as you still have CPU resources left, a nice process will continue to use as much CPU time as it can and requires. Only if your CPU is overloaded (meaning that your running processes request in total more CPU time than you can offer), nice processes will step back and let the CPU give normal or un-nice processes more priority.

1

If you want to nice only bzip choose first version.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .