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 have a list of directories that I'd like to delete. However when I do them all at one, load spikes on the box. Does anyone have an example of a script that would wait until load was under a certain level before proceeding with the deletion (interation of the loop)

share|improve this question

2 Answers 2

ionice is probably the best/simplest solution, but its only really delaying the inevitable and potentially just mean prolonged medium load versus a short run of high load.

There is a good write up here http://www.depesz.com/2010/04/04/how-to-remove-backups/ on a systematic controlled approach.

Changing the io scheduler, removing journals, atime and diratime are also contributory factors. There is also a different deletion binary fastrm , you can find the man here http://linux.die.net/man/1/fastrm

Don't try this at home

A while ago, we were testing faster deletion methods of deletion for terabytes of data. In the end it actually proved quicker to start a rm or mv then interrupt the process with ^c. Then restart the machine with a forced fsck - which then would clean up the inodes and free up the subsequent space on the file system.

It worked surprisingly well and far quicker than a traditional delete - but I would never ever do it on a production system. Ever.

share|improve this answer
1  
Note: ionice only works with the default CFQ scheduler. –  ewwhite Sep 27 '12 at 21:51

Better still, use ionice.

ionice -c3 ./deletion-script

This'll cause your delete command only to run when the disk IO is free, so it has the lowest priority. Cyberciti has a nice little article on all the variants you have, and how to use them.

share|improve this answer
    
Tried it - still caused load to spike. Its a very busy box. –  ckliborn Sep 27 '12 at 21:40
    
Do you have cPanel? cPanel has a binary called cpuwatch designed for exactly this, but I haven't stumbled across a free equivalent. –  Jay Sep 27 '12 at 21:43
    
You should check cpulimit daemon (cpulimit.sourceforge.net) –  lik Sep 27 '12 at 21:47
    
It sometimes helps to use both "nice" and "ionice" on top of each other. Depends a bit of the exact flavor of Unix and the specifics of the system you are running, but if it works in your case it would be a quick and dirty easy solution. –  Tonny Sep 27 '12 at 21:50
    
@lik cpuwatch allows you to specify a load average values, which is a little different to cpulimit which is more about cpu time. –  Jay Sep 27 '12 at 21:54

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.