News for hackers. Stuff that matters.
Re:GNU Parallel 2018 by tbrock on Saturday August 17, 2019 @06:19PM (#20726791)
It’s a shame that this tool is so incredibly useful but simultaneously so unergonomic to use that it requires a 12 page manual.

Every time I reach for it the magical incantations that finally get it working properly are so completely unmemorable that it’s begging to have a modern replacement (like httpie is to curl).

If someone wrote a version with a better interface it would be instantly adopted in preference to this. Might be a good weekend project.

Re:GNU Parallel 2018 by faitswulff on Saturday August 17, 2019 @06:59PM (#20726981)
> ..a 12 page manual.

My first thought was, "12 pages isn't so bad." Then I loaded the page and realized you had a typo and meant _112_ page manual.

That is enough to scare me off of trying to use parallel for casual tasks.

Re:GNU Parallel 2018 by LeoPanthera on Saturday August 17, 2019 @07:26PM (#20727090)
I routinely use it for casual tasks and I've never read the manual. Don't confuse complexity with difficulty.
Re:GNU Parallel 2018 by gnulinux on Saturday August 17, 2019 @10:16PM (#20727808)
> That is enough to scare me off of trying to use parallel for casual tasks.

Just because emacs is such a complex software, does that mean no one can start learning it? No. As far as GNU parallel goes simply just understand what `:::` operator does and you can start using it in your workflow today. Software is not complex for the sake of beginners, it is complex so experts have a higher variety of features.

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @04:56AM (#20729070)
Maybe the cheat sheet is made for you: https://www.gnu.org/software/parallel/parallel_cheat.pdf
Re:GNU Parallel 2018 by jarfil on Saturday August 17, 2019 @06:36PM (#20726868)
The biggest problem with parallel is not the implementation but the command line options specification. The shell has no generic way of defining multiple streams feeding multiple placeholders, so parallel ends up using its own syntax which has to be different in order not to interfere with the base shell syntax. If the same functionality was integrated directly into the shell, it could be less complicated and more generic.
Re:GNU Parallel 2018 by tbrock on Saturday August 17, 2019 @06:46PM (#20726925)
Exactly. The implementation is fine, it’s the interface that isn’t great.
Re:GNU Parallel 2018 by kylek on Saturday August 17, 2019 @06:23PM (#20726805)
Maybe not any better syntax, but xargs is usually installed by default in most distros, and I've never found parallel to be advantageous over it. I don't think this particular wheel needs to be invented again.
Re:GNU Parallel 2018 by ravoori on Saturday August 17, 2019 @06:58PM (#20726977)
xargs does nothing to prevent interleaving of output from simultaneously executed commands.
Re:GNU Parallel 2018 by kylek on Saturday August 17, 2019 @09:45PM (#20727694)
I suspect that's intended behavior. But if I'm understanding correctly, I think you could account for it with something like-

... | xargs -P10 -i sh -c 'command {} 1>{}.out 2>{}.err'

or maybe with tee:

... | xargs -P10 -i sh -c 'command {} | tee -a {}.out'

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @04:59AM (#20729080)
It would require your input not to have any special shell chars - e.g. no space.

It is definitely not something I would dare to run in production.

Re:GNU Parallel 2018 by waterhouse on Saturday August 17, 2019 @07:16PM (#20727053)
Yes. I use parallel if I need coherent output; otherwise I use xargs (which is significantly faster).
Re:GNU Parallel 2018 by lelf on Sunday August 18, 2019 @05:56AM (#20729289)
> xargs is usually installed by default

xargs is part of POSIX, so it should be everywhere.

(-P/-n are not, but both GNU and BSD versions do support it.)

Re:GNU Parallel 2018 by tbrock on Saturday August 17, 2019 @06:29PM (#20726834)
xargs is great but doesn’t run the commands in parallel or chunk input does it?
Re:GNU Parallel 2018 by kylek on Saturday August 17, 2019 @06:36PM (#20726867)
-P sets parallelism, -n number of arguments for each execution. Those are my main weapons. (-i is usually also necessary, and can allow for some pretty creative situations)
Re:GNU Parallel 2018 by hyperpallium on Sunday August 18, 2019 @12:41AM (#20728273)
I don't swear on HN, but Holy Shit, I just added -P to xargs in a testsuite bash script, and it's 7 times faster.

I only have quad core, but -P values higher than 4 give better performance. Maybe because the tests take different amounts of time, and it avoids them backing up. To get x7, I had -P equal to the number of tests.

Re:GNU Parallel 2018 by waterhouse on Monday August 19, 2019 @02:43PM (#20740506)
If the tests are ever waiting for I/O or something, or otherwise using less than one full CPU core, then I think that could explain why running more than the number of cores would be an improvement. If you run "top", or use the "time" utility, what fraction of a CPU core does each test use?
Re:GNU Parallel 2018 by hyperpallium on Tuesday August 20, 2019 @05:48AM (#20745156)
Good thinking, but they don't do any file io, and I'm not sure how it could use less than a full CPU (wouldn't it just finish sooner? Though waiting for io could do that). OTOH it's java (on android, so dex format) and does some classloading of user classes... so maybe that is io? Here's time results:

  real    0m1.818s
  user    0m2.020s
  sys     0m0.900s
top. (It completes in 1 sec, so put in a while loop - BTW top isn't behaving normally, "1" not giving multiple CPUs and not fitting on screen). Jus the top line:

  User 51%, System 23%, IOW 0%, IRQ 0%
Re:GNU Parallel 2018 by icebraining on Saturday August 17, 2019 @07:45PM (#20727169)
It does. What xargs can't do is run stuff in parallel across many machines.
Re:GNU Parallel 2018 by emmelaich on Saturday August 17, 2019 @08:48PM (#20727459)
Yeah, you'd have to combine it with something like

https://github.com/erikfrey/bashreduce

Re:GNU Parallel 2018 by fmajid on Sunday August 18, 2019 @04:06AM (#20728907)
Or pssh
Re:GNU Parallel 2018 by saxonww on Saturday August 17, 2019 @06:35PM (#20726865)
It can, check the -n and -P arguments.
Re:GNU Parallel 2018 by gkfasdfasdf on Saturday August 17, 2019 @06:36PM (#20726877)
xargs can do both and it rocks. https://www.google.com/search?q=xargs+parallel
Re:GNU Parallel 2018 by fmajid on Sunday August 18, 2019 @04:05AM (#20728902)
I dislike parallel’s confusing options, but xargs does not report on progress.
Re:GNU Parallel 2018 by dahart on Saturday August 17, 2019 @08:35PM (#20727395)
> It’s a shame that this tool is so incredibly useful but simultaneously so unergonomic to use that it requires a 12 page manual.

It doesn’t require reading the whole manual, nor does the length of the manual have anything to do with parallel’s ergonomics.

Do you use bash or ssh? Have you looked at the length of those manuals? Most of parallel’s manual is advanced workflows the casual user doesn’t need, stuff like parallel commands run over a network of machines and collecting the results on the originating host.

Maybe you could show some examples of what you mean, because I think parallel is pretty easy to use. Personally I feel like it’s usually easier than Xargs, especially when dealing with tricky quoting. It does have some of it’s own syntax, like the triple-colon :::, and it’s really easy to use. Several pages of manual are about variable substitutions you can use if you want, they’re very similar to bash variable substitutions, and they’re all optional and super convenient. A bunch of parallel’s manual pages are devoted to simple examples, which is nice, and the kind of thing that’s missing from so many man pages.

> it’s begging to have a modern replacement

I’m not sure what “modern” means. You could certainly propose some changes though, or show some examples of the kind of syntax that isn’t working for you. Httpie and curl are built to do different things.

Re:GNU Parallel 2018 by Mizza on Saturday August 17, 2019 @08:36PM (#20727404)
If you're interested, I've written a tool called `loop` which sacrifices some of the abilities of GNU Parallel for a far more intuitive interface (I think so, anyway.)

You can check it out here:

https://github.com/Miserlou/Loop

Re:GNU Parallel 2018 by dahart on Saturday August 17, 2019 @08:58PM (#20727500)
> sacrifices some of the abilities of GNU Parallel

Like... the ability to run things in parallel?

Loop looks nice, don’t get me wrong. I think I’ll try it! It just seems like comparing it to Parallel is misplaced here, and a bad idea in general, since they’re not remotely related. Ole is comparing all these utilities to Parallel to show how general Parallel can be, and suggest you only need his one program and one syntax to emulate hundreds of different utilities: his argument is implicitly that people should use Parallel and not loop.

Re:GNU Parallel 2018 by Mizza on Saturday August 17, 2019 @09:30PM (#20727654)
Yeah, but that syntax is:

$ yes | parallel -N0 -j1 echo touch '{= $_=seq()*5 =}'.txt

vs

$ loop --count-by 5 -- touch $COUNT.txt

UNIX is about using the right tool for the right job, not the same tool for every job.

Let us remember the koan:

A Unix novice came to Master Foo and said: “I am confused. Is it not the Unix way that every program should concentrate on one thing and do it well?”

Master Foo nodded.

The novice continued: “Isn't it also the Unix way that the wheel should not be reinvented?”

Master Foo nodded again.

“Why, then, are there several tools with similar capabilities in text processing: sed, awk and Perl? With which one can I best practice the Unix way?”

Master Foo asked the novice: “If you have a text file, what tool would you use to produce a copy with a few words in it replaced by strings of your choosing?”

The novice frowned and said: “Perl's regexps would be excessive for so simple a task. I do not know awk, and I have been writing sed scripts in the last few weeks. As I have some experience with sed, at the moment I would prefer it. But if the job only needed to be done once rather than repeatedly, a text editor would suffice.”

Master Foo nodded and replied: “When you are hungry, eat; when you are thirsty, drink; when you are tired, sleep.”

Upon hearing this, the novice was enlightened.

Re:GNU Parallel 2018 by asdfasgasdgasdg on Saturday August 17, 2019 @09:56PM (#20727741)
I feel you, but at the same time, this discussion is about GNU Parallel. A tool that does not execute things in parallel is an irrelevancy in this context.
Re:GNU Parallel 2018 by rmetzler on Sunday August 18, 2019 @02:33AM (#20728618)
The name loop implies it runs the jobs sequentially, while the main feature of GNU parallel is to run the jobs in parallel. Maybe this is also possible with loop, but I don't see that option.
Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @05:37AM (#20729227)
I think your example is wrong:

$ seq 0 5 100000 | parallel touch {}.txt

Or you you really want the infinite loop:

$ yes | parallel touch '{= $_=seq()*5 =}'.txt

'$' must be quoted

$ loop --count-by 5 -- touch '$'COUNT.txt

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @05:01AM (#20729091)
Re:GNU Parallel 2018 by degraafc on Sunday August 18, 2019 @08:22AM (#20729767)
Looks more like a souped up `watch` [1] than `parallel` to me. Nice tool!

[1]: https://en.wikipedia.org/wiki/Watch_(Unix)

Re:GNU Parallel 2018 by gioele on Sunday August 18, 2019 @03:46AM (#20728825)
For those afraid of the complexity of GNU Parallel, there is the tiny moreutils `parallel` (or Tollef's parallel) that covers 90% of the common use cases with a single-page manual.

https://manpages.debian.org/testing/moreutils/parallel.1.en....

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @04:51AM (#20729056)
But looking at the comparison, do you really find GNU Parallel that much harder to understand?

  parallel sh -c "echo hi; sleep 2; echo bye" -- 1 2 3

    parallel echo hi";" sleep 2";" echo bye ::: 1 2 3

  parallel -j 3 ufraw -o processed -- *.NEF

    parallel -j 3 ufraw -o processed ::: *.NEF

  parallel -j 3 -- ls df "echo hi"

    parallel -j 3 ::: ls df "echo hi"
And if you are looking for the single page overview, why not link to the cheat sheet: https://www.gnu.org/software/parallel/parallel_cheat.pdf
Re:GNU Parallel 2018 by benbenolson on Saturday August 17, 2019 @06:35PM (#20726861)
Why does the language that it's written in matter? For most users, it's a compiled binary sitting on your system.

EDIT: Parent comment edited his post, leaving out his personal preference of language.

Re:GNU Parallel 2018 by fmajid on Sunday August 18, 2019 @04:08AM (#20728912)
Parallel is written in Perl, not a compiled binary. That may be what he was referring to. I also wish Perl (and ruby, and Java) would go away.
Re:GNU Parallel 2018 by PeCaN on Saturday August 17, 2019 @08:40PM (#20727421)
> it’s begging to have a modern replacement (like httpie is to curl).

This seems like a pretty weird example. All common tasks in curl are very straightforward and I've never even heard of httpie.

Let's please not change the interface to basic command line tools every few years because people want something ""modern"".

Re:GNU Parallel 2018 by brians on Saturday August 17, 2019 @11:30PM (#20728066)
Common tasks for the web are easy in curl—though it will take me a long time to forget environment variables that could be set to false, true, or two. Httpie makes web apis easier, with better support for api keys and for hashing some headers into others, holding state across several command invocations, that sort of thing.
Re:GNU Parallel 2018 by msla on Saturday August 17, 2019 @09:21PM (#20727608)
Realistically, the best language for this is C, because everything else is too heavyweight, requires too much of a runtime, or simply isn't available most places.
Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @05:08AM (#20729116)
Does that also apply to platforms where you as a consultant for hire does not have access to a C compiler for that given platform?

It used to be an issue that non-free UNIXes did not include a C-compiler by default, and then C would really not help. I am not sure if that is the case anymore.

Re:GNU Parallel 2018 by RubberSoul on Saturday August 17, 2019 @08:53PM (#20727468)
There are great videos for understanding how it works [0]. I watched a couple of those and after that was able to do exactly what I needed.

For me the trickiest thing is remembering how to deal with redirection. I find the --dry-run option to be super useful when setting up a command.

[0]: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @05:03AM (#20729101)
Yeah, quoting redirection is a bitch, but as long as you know GNU Parallel is just a program and not part of the shell, you can usually deduct which parts will be interpreted by the shell before GNU Parallel gets it.

I often create bash functions to avoid that shit, and then call the bash functions from GNU Parallel instead.

Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @04:47AM (#20729043)
I think the cheat sheet is made for you: https://www.gnu.org/software/parallel/parallel_cheat.pdf

If you have a hard time getting it to work and remember how, then it is likely that the fundamentals of GNU Parallel are not clear to you. Chapter 2 ("Learn GNU Parallel in 15 minutes") of the book should take care of that.

> a better interface

That is often a tough one. I, for one, like emacs' interface. Others despise it. So when you write 'better interface' I think it will be helpful if you were more specific.

Re:GNU Parallel 2018 by yesco on Saturday August 17, 2019 @07:21PM (#20727075)
Well I had never heard of httpie before now so thanks for casually dropping that endorsement. Never realized how much I wanted something like this.
Re:GNU Parallel 2018 by feanaro on Saturday August 17, 2019 @06:22PM (#20726800)
I agree with the sentiment, but please, Rust, not Go. In fact, I remember seeing such a project, let me search...

Ah, here it is: https://gitlab.redox-os.org/redox-os/parallel

Re:GNU Parallel 2018 by krapht on Saturday August 17, 2019 @06:40PM (#20726899)
What? Why? Seriously getting fed up with the Rust lovers in Hacker News. It makes me hate Rust even though I actually really like it as a modern replacement for C++. Memory safety is only one aspect of proving program correctness. It's also less of an issue for garbage collected languages, and tracing GCs are fairly performant.

You don't see Coq users crapping on other languages for not proving their programs correct according to a formally defined specification.

Re:GNU Parallel 2018 by 13415 on Saturday August 17, 2019 @06:46PM (#20726924)
The Rust community is the main reason why I don't use Rust.
Re:GNU Parallel 2018 by sigmonsays on Saturday August 17, 2019 @06:45PM (#20726919)
lets not start a language war here
Re:GNU Parallel 2018 by hi41 on Saturday August 17, 2019 @07:44PM (#20727166)
Could you please elaborate on why Rust would be better than Go? Doesn’t Go offer good support for parallelism, which would be great use for implementing GNU Parallel.
Re:GNU Parallel 2018 by mechanical_jane on Sunday August 18, 2019 @05:47AM (#20729259)
Some of the alternatives to GNU Parallel are written in Go: https://www.gnu.org/software/parallel/parallel_alternatives....

Speed wise they are comparable to GNU Parallel. So the argument for Rust could be speed.

The argument against Rust could be backwards compatibility: How would you do the {= perl expr =} thing? Will it run on the current targets (CentOS 3.9 according to https://www.gnu.org/software/parallel/parallel_design.html#O...)? Will it run on systems for which you as a consultant do not have access to a Rust compiler for?

Re:GNU Parallel 2018 by tbrock on Saturday August 17, 2019 @06:37PM (#20726879)
Ok, whichever language.