Skip to content

Commit 8663445

Browse files
committed
[Fix #10] Throttle client polling to avoid GET floods
After an HTTP request that returns no results, block on the incoming queue for up to 100ms before retrying. This limits idle polling to ~10 requests/sec while still returning results immediately when they're available.
1 parent 9c6bdb9 commit 8663445

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/drawbridge/client.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
(or (.poll incoming 0 TimeUnit/MILLISECONDS)
4848
(when (pos? timeout)
4949
(http)
50-
(recur (- timeout (- (System/currentTimeMillis) t)))))))
50+
(or (.poll incoming (min timeout 100) TimeUnit/MILLISECONDS)
51+
(let [remaining (- timeout (- (System/currentTimeMillis) t))]
52+
(when (pos? remaining)
53+
(recur remaining))))))))
5154
http
5255
(fn close []))))
5356

0 commit comments

Comments
 (0)