Reynald Borer
2018-07-02 11:06:36 UTC
Hi everyone,
I'm currently integrating Aleph (client part) into a platform built on
Kafka messaging bus in order to crawl a lot of URLs. To prevent loss of
messages and handle spikes of load, I need to handle back-pressure to
throttle Kafka messages consumption when Aleph is busy.
To achieve that, I've built a solution on top of a java Semaphore, in order
to allow for a maximum of X concurrent crawling requests at a time (I
couldn't find any other way to achieve this with either Aleph or Manifold).
Here is a (very simplified) example of code I am using:
(defn crawl
[^Semaphore s url]
; blocking if full
(.acquire s)
(try
(-> url
(http/get {:option :goes :here :dummy})
(d/chain'
(do-some-processing-here))
(d/catch' Exception
(exception-handler-here))
(d/finally'
(.release s)))
(catch Exception e
(.release s)
(d/error-deferred e))))
Now here comes the problem: it seems to randomly *not* release a Semaphore
permit, like if the chain doesn't go until the end!
In my calling code, I don't do anything with the returned deferred (that
is, it is never deferenced). I assume that once I have called my crawl
function, the execution happens in a separate thread so I don't need to do
anything with the returned deferred.
This issue is starting to drive my crazy. Is this supposed to work as I
expect it or I have completely misunderstood deferred principle?
Thanks in advance if you're able to shed some light on my problem.
Cheers,
Reynald
I'm currently integrating Aleph (client part) into a platform built on
Kafka messaging bus in order to crawl a lot of URLs. To prevent loss of
messages and handle spikes of load, I need to handle back-pressure to
throttle Kafka messages consumption when Aleph is busy.
To achieve that, I've built a solution on top of a java Semaphore, in order
to allow for a maximum of X concurrent crawling requests at a time (I
couldn't find any other way to achieve this with either Aleph or Manifold).
Here is a (very simplified) example of code I am using:
(defn crawl
[^Semaphore s url]
; blocking if full
(.acquire s)
(try
(-> url
(http/get {:option :goes :here :dummy})
(d/chain'
(do-some-processing-here))
(d/catch' Exception
(exception-handler-here))
(d/finally'
(.release s)))
(catch Exception e
(.release s)
(d/error-deferred e))))
Now here comes the problem: it seems to randomly *not* release a Semaphore
permit, like if the chain doesn't go until the end!
In my calling code, I don't do anything with the returned deferred (that
is, it is never deferenced). I assume that once I have called my crawl
function, the execution happens in a separate thread so I don't need to do
anything with the returned deferred.
This issue is starting to drive my crazy. Is this supposed to work as I
expect it or I have completely misunderstood deferred principle?
Thanks in advance if you're able to shed some light on my problem.
Cheers,
Reynald
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.