Problem:
Linux “find” is a very versatile command, but most of the time it’s also quite a resource hog. Not a problem if you’re calling it occasionally on your desktop, but using it croned on a server can significantly degrade the system performance. No surprise indeed as it’s searching through all the files in the specified tree. But it’s also very useful at times. In my case, not using it was not an option, but I had to find a way to distribute its resource usage more evenly, even at the cost of increasing the execution time.
Solution:
Find has a very handy option, namely -exec. So let’s assume we have a very simple normal call like this:
find ./ -name example
This kind of a call can be quite intensive for the CPU/HDD tandem. So let’s try making it more pleasant for the server:
DELAY=0.1
find ./ -name example -exec sleep ${DELAY} \; -print
This way on every iteration an additional sleep delay is introduced. The amount of delay has to be tweaked individually according to the system performance, accepted spikes in CPU/HDD usage, desired execution time and so on. Just remember, that it’s not a 100% solution and it can lead to enormously long running time. But at times, this kind of background process can be quite handy.






0 Responses to “Linux find command – reducing resource usage”