Many old Unix hands will be _very_ familiar with the process of building up a 
pipeline...

For example find all corrupted bz2 packages in a directory....
  find /var/apt-cacher -name '*.bz2' | xargs bunzip2 -tv

Or finding an email in your archives....

  find ~/oldmail -type f | xargs zgrep -i 'some keyphrase'

..to give two very simple very standard sorts of examples...

Now, if you have a dual core (like me) or higher processor... watch
what happens to your CPU load with something like gkrellm.

Only one core is doing all the work.


The man page says...
       --max-procs=max-procs, -P max-procs
              Run up to max-procs processes at a time; the default is 1.  If 
max-procs is 0, xargs  will  run
              as many processes as possible at a time.

Well, lets make things happen twice as fast....

  find ~/oldmail -type f | xargs -P 2 zgrep -i 'some keyphrase'

Whoops... That didn't work. Still only keeping one core busy.

Lets see what happen...

  find ~/oldmail -type f | xargs -P 2 echo ---------MARKER----------- zgrep -i 
'some keyphrase'

---------MARKER----------- zgrep -i 'some keyphrase' file.1 file.2 file.3 
.......

Aha! xargs packed _all_ the files onto the command line of one zgrep
instance, it didn't need to invoke a second.

In fact, if only I had finished reading the man page...
     Use the -n option with -P; otherwise chances are that only one exec will 
be done.
I would have known that!

Let's try that again...

  find ~/oldmail -type f | xargs -P 2 -n 1 zgrep -i 'some keyphrase'

Hmm. That's creating hundreds of setups and tear downs for zgrep. How about...

  find ~/oldmail -type f | xargs -P 2 -n 5 zgrep -i 'some keyphrase'

Yip. Good balance. Both cores busy full time on useful work.


John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : [EMAIL PROTECTED]
New Zealand

Reply via email to