Skip to content

Commit

Permalink
[#270] Adaptive Ajax send retry
Browse files Browse the repository at this point in the history
Slightly smarter strategy re: waiting for possible Ajax repolling.

In particular, should provide more reliable async broadcasting to
Ajax clients on poor connections that take very long to repoll. In
these cases, send buffering should also be increased.

Note that this doesn't change the general advice given in #270.
Applications that need guaranteed async broadcasts should still use
an appropriate application-level ack design when possible.
  • Loading branch information
ptaoussanis committed Oct 2, 2016
1 parent 7925ddc commit 7f2a884
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/taoensso/sente.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,7 @@
Allows some time for possible Ajax poller reconnects."
[conns_ uid buffered-evs-pstr]
(tracef "send-buffered-server-evs>ajax-clients!: %s" buffered-evs-pstr)
(let [nmax-attempts 7
ms-base 90
ms-rand 90
;; (* 7 (+ 90 (/ 90 2.0))) ~= 945ms

(let [ms-backoffs [90 180 360 720 1440] ; Mean 2790s
;; All connected/possibly-reconnecting client uuids:
client-ids-unsatisfied (keys (get-in @conns_ [:ajax uid]))]

Expand Down Expand Up @@ -746,11 +742,12 @@
now-satisfied (into client-ids-satisfied ?newly-satisfied)]

;; (tracef "now-satisfied: %s" now-satisfied)
(when (and (< n nmax-attempts)
(some (complement now-satisfied) client-ids-unsatisfied))
;; Allow some time for possible poller reconnects:
(<! (async/timeout (+ ms-base (rand-int ms-rand))))
(recur (inc n) now-satisfied))))))))
(when-let [ms-backoff (get ms-backoffs n)]
(when (enc/rsome (complement now-satisfied) client-ids-unsatisfied)
(let [ms-timeout (+ ms-backoff (rand-int ms-backoff))]
;; Allow some time for possible poller reconnects:
(<! (async/timeout ms-timeout))
(recur (inc n) now-satisfied))))))))))

;;;; Client API

Expand Down

0 comments on commit 7f2a884

Please sign in to comment.