Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When using pmap I have found that <b>fairly large chunks are required to overcome the switching and future overhead</b> try a chunk size of 10,000 for an opperation as fast as <code>+</code>. The potential gains are bounded by the overhead of generating the chunks. This results in an optimal value that balances the available cores and the time required to make the chunks. In this case with <code>+</code> as the workload I was unable to make this faster than the single threaded option. </p> <p>If you're interested in doing this without pmap and potentially using fork/join check out the new(ish) <a href="http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html">reducers library</a></p> <p>The OOM situation comes from the first test realizing the lazy sequence from <code>(range n)</code> which is then retained so it can be passed to the second sequence.</p> <p>If I make the + function much slower by defining a <code>slow+</code> function and use that the diference between single thread, pmap over chunks, and reducers w/ forkJoin become visable: </p> <pre><code>user&gt; *clojure-version* {:major 1, :minor 5, :incremental 0, :qualifier "RC15"} (require '[clojure.core.reducers :as r]) (def workers (+ 2 (.. Runtime getRuntime availableProcessors))) (defn slow+ ([] 0) ([x] x) ([x y] (reduce + (range 100000)) (+ x y))) (defn run-test [] (let [n 8000] (time (reduce slow+ (range n))) (time (reduce slow+ (pmap #(reduce slow+ %) (partition-all (* workers 100) (range n))))) (time (r/fold slow+ (vec (range n)))))) user&gt; (run-test) "Elapsed time: 28655.951241 msecs" ; one thread "Elapsed time: 6975.488591 msecs" ; pmap over chunks "Elapsed time: 8170.254426 msecs" ; using reducer </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload