BrunoBonacci / safely

Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
https://cljdoc.org/d/com.brunobonacci/safely
Apache License 2.0
230 stars 9 forks source link

Counter intuitive exponential backoff #9

Closed jasonjckn closed 3 weeks ago

jasonjckn commented 1 year ago

Counter intuitive exponential backoff

(take 10 (#'safely.core/exponential-seq 100)) ;; => (100 100 100 100 100 100 100 100 100 100)

This had my mind scratching for 5 minutes, wondering if I was using your library wrong, not very exponential.

Why not

delay = base-delay * 2 ^ (retry-number - 1) +/- random-variation
BrunoBonacci commented 1 year ago

[corrected]

Indeed it is counterintuitive.... The formula I came up with follows the idea: "Do what I mean, not what I said"

In this page there is a full explanation of the formula and the expected behaviour https://github.com/BrunoBonacci/safely#random-exp-backoff

Sorry, I misinterpreted your formula and sent you an incorrect response on earlier message

Indeed your solution works and I will plug it in the next release.

BrunoBonacci commented 3 weeks ago

Released with 1.0.0