What is `xargs -P 0` exactly doing, and is it a good idea to use it?

xargs provides a command xargs -P 0, the doc mentions that is spawns as many processes as possible to run the commands in parallel. But is it stopping, e.g., at the number of available CPU, or litterally several tens of thousands of threads? If it is the second option, isn’t it less efficient than spawning around the number of CPU threads? I guess constantly changing between processes can take a non-negligeable time right?

Asked By: tobiasBora

||

I ended up doing the test myself. So -P 0 does try to run all processes at the same time (the limit being around the maximum number of allowed threads per the OS, which can be several thousands, I think), but it is a very bad idea to use it on CPU intensive tasks as this makes the system really slow.

I tested with around 200 pdflatex processes, and the overall running time is actually higher (2:05mn instead of 1:10mn) than with -P 16 on my process when using 200 processes (I guess the additional time to switch between processes explains this). Moreover, with -P 0 the whole OS is laggy and hard to use which is not the case with -P 16. (My cpu has 8 CPU threads.)

Answered By: tobiasBora
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.