148 points · by 0xmohit · 10y ago · 63 comments
But this does claim to be a reimplementation of much of GNU Parallel's functionality. If it's compatible, maybe there isn't too much of an issue.
In the interest of silly UNIXism, I hereby vote for the name "serial" instead. It's just like "more" and "less", right?
There is no need for threads. Just spawn background processes:
echo 1 &
echo 2 &
wait
echo 3 &
wait
echo 4 &
...
The key is that the wait() system call will hang until any child process finishes.It's like discovering that "ls" is spawning 5 threads for internal communication.
In particular there is no sane way to async waitpid() on POSIX.
[0] https://www.jonathanturner.org/2015/10/lessons-from-first-12...
I added an exception as I pretty much always do but in case the owner of the site is around here, they might want to investigate this.
g1:
job1
g2:
job2
and then one goal to depend on them all and I used make -j 4> parallel dates back to around the same time. It was originally a wrapper that generated a makefile and used make -j to do the parallelization.
find . -type f -name | parallel --jobs 5 process_file
That will run "process_file foo" for ever file in a directory with 5 processes running in parallel. find . -type f -name | xargs -I {} -n 1 -P 5 process_file {} parallel --progress --wd '.' -S '4/fourworkers@blehworker.org,8/eightworkers@eightworkers.org,2/:' "./complicated_command --param1={1} --param2={2} ::: $(some_shellcommand_to_generate_param1_values.sh) ::: $(some_shellcommand_to_generate_param2_values.sh)
It's very flexible, become my go-to for speeding up parallelizable work. Next step up would be Celery or Spark or something.The code is 427 lines of C. GNU parallell is 10k+ lines of perl. Considering mmstick compares the loading times, it's easy to see where the difference comes from.
It lets you code your own replacement string (using --rpl), and lets you make composed commands with shell syntax:
myfunc() { echo joe $*; }
export -f myfunc
parallel 'if [ "{}" == "a" ] ; then myfunc {} > {}; fi' ::: a b c
It does not need a special compiler, but runs on most platforms that have Perl >=5.8. Input can be larger than memory, so this: yes `seq 10000` | parallel true
will not cause your memory to run full.You can read a lot more about the design in `man parallel_design` and see the evolution of overhead time per job compared to each release on: https://www.gnu.org/software/parallel/process-time-j2-1700MH...
In other words: Treat GNU Parallel as the reliable Volvo that has a lot of flexibility and will get the job done with no nasty corner case surprises.
It is no doubt possible to make a better specialized tool for situations where the overhead of a few ms per job is an issue and where you neither need brakes, seatbelts nor airbags. xargs is an example of such a tool, and you can have both GNU Parallel and xargs installed side by side.
A few years ago, debian made GNU parallel provide the "/usr/bin/parallel" executable, instead of moreutils. The maintainer of moreutils had some interesting things to say about that: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597050#75
Only 5k? :D
But, yes, the criticisms are valid. I recommend moreutils.
While this is technically correct, it is misleading: GNU Parallel existed before it became GNU. See details on: https://www.gnu.org/software/parallel/history.html
To add to this, parallel mentions as much in its man pages (that there is a certain startup cost, and a certain job-startup cost), and offers tips for speeding up the processing of jobs which exit fairly fast. But there's no reason you couldn't also do those things in the Rust version, so it's going to win every time. When dealing with commands which take a while to complete though, the extra overhead of the perl script would probably be negligible.
GNU Parallel has --joblog and can continue from where it left off or retry all failed jobs again.