Reputation: 8562
I am wondering what is the best way to implement performance counters in Clojure for a particular task that runs concurrently.
I usually end up having something like this:
(defn -main [& args]
(let [c (async/chan)]
(doseq [_ (range 50)]
(async/thread
(async/>!! c
(doseq [r (chunk-of-work)]
(println r)
(doall (pmap #(work %) r))))
)
)
)
(while true
(async/<!! c))
)
)
What would be the best way of counting how many messages I am getting through the channel every second? The code is indented for better readability.
Upvotes: 0
Views: 165
Reputation: 9886
Have you considered ztellman's Narrator. It's a package for
"analyzing and aggregating streams of data"
There's plenty of examples, including one for the rate of messages over a period.
I haven't actually used it, just remembered reading its docs and it having this kind of aggregation build in.
Upvotes: 1