Guest User

Untitled

a guest
Jul 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. (ns batch-pmap-wide-finder
  2. "A basic map/reduce approach to the wide finder using agents.
  3. Optimized for being idiomatic and readable rather than speed.
  4. Updated to deal with batches of lines instead of individual lines.
  5. "
  6. (:use [clojure.contrib.duck-streams :only [reader]]
  7. [clojure.contrib.seq-utils :only [partition-all]]))
  8.  
  9. (def *batch-size* 50)
  10.  
  11. ;;(def re #"GET /\S+-(\d+)-\S+ ")
  12. (def re #"GET /(\d+) ")
  13.  
  14.  
  15. (defn tally [line]
  16. (if-let [[_ hit] (re-find re line)]
  17. {hit 1}
  18. {}))
  19.  
  20.  
  21. (defn count-lines
  22. [lines]
  23. (apply merge-with + (map tally lines)))
  24.  
  25.  
  26. (defn find-widely
  27. "Return a map of pages to hit counts in filename."
  28. [filename]
  29. ;; each agent begins as an empty map.
  30. (apply merge-with +
  31. (pmap count-lines (partition *batch-size*
  32. (line-seq (reader filename))))))
  33.  
  34. ;; Main
  35. (. System/out println
  36. (str (find-widely (first (rest *command-line-args*)))))
Add Comment
Please, Sign In to add comment