throttler
throttler copied to clipboard
Throttle based on concurrency
feature request: consider a plain concurrency limit (so eg: max burst of 1000 but at most 50 at a time).
Really like this library btw, good job!
Hey @ludwik! I'm glad you're liking throttler.
Actually, I have your feature request already implemented in a local branch already. For life-related reasons I haven't buckled down and pushed it. This feature request may be what I needed to revisit that branch and publish it :)
So no promises on a date, but I'll do my best to release something soon.
Awesome! Looking forward to it.
On this line: https://github.com/brunoV/throttler/blob/master/src/throttler/core.clj#L154 ...is it just a matter of controlling the 1 in the (chan 1). I'm still new to the async thing.
Regards.
Ludwik.
Hi.
Just came back to this 6 months on... I'm doing something like the below, composes well with the throttler.
(defn fn-concurrency-throttler [n-way]
(let [c (async/chan n-way)]
(fn [f]
(fn [& args]
;; The approach is simple: pipe a bogus message through a
;; concurrency-throttled channel. Evaluate the function, and when it completes, take the msg off.
(async/>!! c :eval-request)
(try
(let [answer (apply f args)]
(async/<!! c)
answer)
(catch Exception e (do (async/<!! c) (throw e)))))))) ; in case anything breaks, still take the msg off the channel and rethrow
(defn concurrency-throttler-fn [f n-way]
((fn-concurrency-throttler n-way) f))