cat list_of_file | parallel --load 100% run_intensive_process cat args | parallel this-program {}
parallel this-program {} ::: arg1 arg2 arg3 ...
The only really new thing is ::: which separates the program from the arguments if you want to give them directly. BUGS
[...]
Speed
Startup
GNU parallel is slow at starting up - around 250 ms the
first time and 150 ms after that.
Job startup
Starting a job on the local machine takes around 10 ms.
This can be a big overhead if the job takes very few ms
to run. Often you can group small jobs together using -X
which will make the overhead less significant. Or you
can run multiple GNU parallels as described in EXAMPLE:
Speeding up fast jobs.
And man parallel_alternatives: DIFFERENCES BETWEEN parallel-bash AND GNU Parallel
[...]
parallel-bash is written in pure bash. It is really fast
(overhead of ~0.05 ms/job compared to GNU parallel's ~3
ms/job). So if your jobs are extremely short lived, and
you can live with the quite limited command, this may be
useful.
And https://www.gnu.org/software/parallel/ Over the years GNU parallel has gotten more safety features (e.g. no silent data loss if the disk runs full in the middle of a job). These features cost performance. This graph shows the relative performance between each version.
I really do not care how fast you can produce wrong output. I care how fast you can produce correct output, and I am do not care about a specialized solution that only works for one single specialized task. $ $tm true
It gives the same output as your example, and it is way faster. But do you really feel that is a fair comparison? If you say no, then by your own arguments, I can claim you are "moving the goal posts". $ export LC_ALL=C
$ $tm xargs -0P1 grep $lb t < ../f |sort |md5sum
7.05user 9.88system 0:24.53elapsed 69%CPU (0avgtext+0avgdata 2344maxresident)k
0inputs+0outputs (0major+4960minor)pagefaults 0swaps
8ef2c658a70bb38438e59421231246b9 -
$ $tm xargs -0P16 grep $lb t < ../f |sort |md5sum
10.16user 36.62system 0:18.30elapsed 255%CPU (0avgtext+0avgdata 2332maxresident)k
0inputs+0outputs (0major+4980minor)pagefaults 0swaps
c8ebf840e54ec8b5a49e159eda09e63f -
$ $tm parallel -X0P16 grep $lb t < ../f |sort |md5sum
16.97user 33.94system 0:16.36elapsed 311%CPU (0avgtext+0avgdata 51624maxresident)k
0inputs+2069296outputs (0major+169409minor)pagefaults 0swaps
8ef2c658a70bb38438e59421231246b9 -
It greps for lines containing t, sorts the lines and computes a hash. $ $tm xargs -0P1 grep $lb t < ../f |md5sum
7.03user 9.30system 0:16.32elapsed 100%CPU (0avgtext+0avgdata 2332maxresident)k
0inputs+0outputs (0major+5023minor)pagefaults 0swaps
d89b45188602c9bb08026dc2892cfa75 -
$ $tm parallel -kX0P16 grep $lb t < ../f |md5sum
18.21user 36.03system 0:10.26elapsed 528%CPU (0avgtext+0avgdata 65396maxresident)k
0inputs+2069344outputs (0major+154929minor)pagefaults 0swaps
d89b45188602c9bb08026dc2892cfa75 -
I have not analyzed the output but I think the error is caused by the issue described here: https://mywiki.wooledge.org/BashPitfalls#Non-atomic_writes_w... iwashere() {
sleep $(shuf -i 1-9 | head -1)
date
echo "===> $(hostname) <===" > ~/I_WAS_HERE
}
env_parallel -Sserver-0{1..5} --tag --nonall iwashere
I like that I can try out the function locally before running it remotely.
The {= =} escapes to perl, so you have a full programming language available.