Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a cronjob that is basically nothing more than mysqldump whatever | gzip > backup.sql.gz. The database is fairly big. I've noticed that while the job is running, my apache is much less responsive, the CPU usage is like this

 %CPU  COMMAND 
 15.1  gzip               
 14.1  mysqld             
 13.1  mysqldump 

Is there a way to make this job use less CPU, maybe at the price of it taking longer?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted
 ionice -c 3 nice mysqldump whatever | ionice -c 3 nice gzip > backup.sql.gz
share|improve this answer
    
Although CPU usage quotes remain the same in top, my apache is now much more responsive. I guess this is the way it's supposed to work. Thanks a lot! –  thg435 Dec 20 '11 at 15:19
add comment

You can use nice and renice to change the priority of processes. This will mean they get less access to the CPU.

You probably don't want to renice mysqld but mysqldump and gzip can safely have their priorities changed.

If you're having trouble with too much disk usage, you can use ionice.

share|improve this answer
    
Thanks. This is what I've ended up implementing –  thg435 Dec 20 '11 at 15:19
add comment

If your web app is writing to the 'whatever' database, then it has to wait for mysqldump to complete, because it locks tables by default. If this is the case and you lower the priority, you'll make the problem worse.

Dump the database first as plain text, then run gzip to compress the file. This way mysqldump can complete sooner and release the lock, and MySQL and Apache can go about their business while gzip runs.

share|improve this answer
    
Good idea, thanks. –  thg435 Dec 20 '11 at 15:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.