

Clojure, Multi-core, AWS Cluster Compute & Lattes - brisance
http://dosync.posterous.com/clojure-multi-core-amazon-cluster-compute-lat

======
almost
From the article:

    
    
       (defn ping []
         (-> (http/get "http://localhost:5123" :as :string) 
             :content))
    
        (defn multi-ping []
          (->> (repeatedly 16 #(ping))
               (apply str)))
    

Can anyone tell me what --> and ->> do in this context?  I've been trying to
find out myself but given that they're both impossible to search for on
Google...

~~~
KirinDave
They're called "thrush" but many of us pronounce them "thread" and "thread
end". 

(-> x expr1 expr2 ... exprN) evaluates x, then takes the result and puts it as
the _first_ argument in expr1, evaluates that, and puts the result in the
_first_ argument of expr2, repeating until exprN, where the result is
returned. 

(->> x expr1 expr2 exprN) does the same thing, but instead of making it the
first argument it makes it the _last_ argument of subsequent expressions. 

Clojure's culture generally agrees that the "subject" of function calls should
be the first argument, so in general the -> operator is all you need. 
Sometimes you're shuttling data around, and then ->> comes into play. 

Please note that multi-ping in this is atypical and constructed that way for
didactic purposes (i.e., to be transformed later).  Usually you'd see it as:

    
    
         (defn multi-ping [] (apply str (repeat 16 ping)))
    

For readability, some people might prefer to use a let.  I think with only 2
levels of nesting, it should be pretty easy to see what's up and I wouldn't
bother, but that'd look like:

    
    
        (defn [] multi-ping
            (let [pings (repeat 16 ping)]
                (apply str pings)))

~~~
swannodette
I went ahead and changed my code to use let.  I agree there's no reason to
throw people off on such a simple snippet. 

~~~
almost
Probably a good idea, but thanks anyway for introducing me to another cool
feature of Clojure! 

------
skorgu
I was confused by:

> In fact for $3.20 (the price of a latte) I can play around with Clojure code
> on a high performance 8-core 64bit server for two hours. 

An m2.4xlarge spot instance is ~$0.80/hr and has "26 EC2 Compute Units (8
virtual cores with 3.25 EC2 Compute Units each)". 

Are the cluster instances that much closer to bare metal than 'normal' ec2
instances or am I missing something? 

~~~
swannodette
33.5 EC2 compute units and very low latency between instances.  More details
here:

<http://aws.amazon.com/ec2/hpc-applications/>

~~~
skorgu
I suppose he's going for the 16 cores instead of 8 given the interconnect
isn't used.  It would be interesting to see a performance comparison between
the xlarges and the cluster instances on simple speedups like this.