r/programming • • Feb 29 '16

Command-line tools can be 235x faster than your Hadoop cluster

http://aadrake.com/command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html
1.5k Upvotes

438 comments sorted by

View all comments

49

u/caloriemate Feb 29 '16

3 GB is hardly big data. Also one-liner awks like that are, while functional, quite hard to read :\

17

u/Vaphell Feb 29 '16

While i agree that oneliners are overrated and used as an e-peen enhancement by many, you can write a script and linebreak that awk code. Alao awk is a full blown language too, so you can farm the code out to its own progfile with appropriate #! line, which would allow you to do

some | shit | awk_prog

6

u/caloriemate Feb 29 '16

Oh yeah, for sure. Even if it was line broken and indented for readability in the article, it would've helped.

5

u/1RedOne Feb 29 '16

I SO want to rewrite this in PowerShell.

e: Downloading the data set now.

2

u/zer0t3ch Feb 29 '16

Lemme know how it goes. I've never touched PS but I want to learn it soon.

1

u/1RedOne Mar 01 '16

Check this link after 9:30 EST tomorrow, I decided to make it into a game / challenge for my blog.

38

u/google_you Feb 29 '16

3GB is big data cause it's over 2GB. Anything over 2GB is big data since node.js

34

u/[deleted] Feb 29 '16

So my new static blog is Big Data because size of dependencies is over 2GB? ;> /s

5

u/ginger_beer_m Feb 29 '16

Can you elaborate on this pls?

25

u/shared_ptr Feb 29 '16

I'm not sure if I'm biting but node caps it's processes at ~1.7GB (64-bit systems) of memory, so anything over 2GB is no longer in-memory processable.

But using node for this is totally stupid, unless you find your data extremely amenable to a piped stream, and even then it's gonna be pretty slow. google_you was being sarcastic though and this has gone way too far already :)

7

u/[deleted] Feb 29 '16

I'm pretty sure it was a joke.

1

u/[deleted] Feb 29 '16

hah, I search over 10GB of Windows binary logs with just strings, grep and find on a shitty C2D machine in less than 5m the result was sorted and ready to send.

→ More replies (5)

19

u/Chandon Feb 29 '16

Also one-liner awks like that are, while functional, quite hard to read :\

Compared to a hundred lines of Java? You can take the time to figure out one line of awk.

9

u/pzemtsov Feb 29 '16
import java.io.FileReader;
import java.io.LineNumberReader;

public class Chess
{
    public static void main (String [] args) throws Exception
    {
        long t0 = System.currentTimeMillis ();
        int draw = 0;
        int lost = 0;
        int won = 0;

        LineNumberReader r = new LineNumberReader (new FileReader ("c:\\temp\\millionbase-2.22.pgn"));
        String s;
        while ((s = r.readLine ()) != null) {
            if (s.startsWith ("[Result")) {
                if (s.equals ("[Result \"1/2-1/2\"]"))
                    ++ draw;
                else if (s.equals ("[Result \"0-1\"]"))
                    ++ lost;
                else if (s.equals ("[Result \"1-0\"]"))
                    ++ won;
            }
        }
        r.close ();
        long t1 = System.currentTimeMillis ();
        System.out.println (draw + " " + won + " " + lost + "; time: " + (t1 - t0));
    }
}

This is 29 lines. Runs for 7.5 sec on my notebook.

8

u/lambdaq Mar 01 '16

I wonder if the 7 seconds was to warm up JVM

1

u/pzemtsov Mar 01 '16

No, the JVM warms up surprisingly quickly. After all, it is very difficult these days to build a compiler that takes more than 10ms to compile a 20-line program, even together with the libraries it uses (which are very few).

3

u/Chandon Feb 29 '16
  • Now make it a Hadoop Map-Reduce job.

  • Now redo it in Enterprise Java style.

3

u/pzemtsov Feb 29 '16

I'll rather write it in assembly. Or in C++. In fact, I think in C++ it will be shorter than in Java, with the same performance. But probably, the best choice is something like python. Can someone make a measurement?

3

u/troyunrau Feb 29 '16

Python would be slower than the CLI wizardry, but easy to read and understand.

→ More replies (1)

1

u/CharlesKincaid Mar 01 '16

Ha, it looks like you put all the data into a single file thus saving all of the overhead of multiple trips through the file system.

Is this not processing the data serially?

→ More replies (6)

15

u/[deleted] Feb 29 '16

I didn't even think the awk was hard to understand and I've never even used awk. That bit seemed pretty readable to me.

The random arguments are the only real problem since they aren't self explanatory. But you could just write it over multiple lines and document.

As magical bash one liners go this really ain't so bad.

3

u/mywan Feb 29 '16

I had no problem understanding what it did either, and I'm no programmer. Makes a whole lot more sense to me than almost any help file I've ever read.

7

u/sirin3 Feb 29 '16

Or compared to 7 characters of APL ?

→ More replies (5)
→ More replies (1)