Class: Tenax::Retry::Backoff::Exponential
- Defined in:
- lib/tenax/retry/backoff/exponential.rb
Overview
Exponential backoff without jitter.
delay = min(cap, base * factor ** (attempt - 1))
Note: pure exponential backoff (no jitter) is generally NOT recommended for production use against shared remote services, because all clients retry at synchronized intervals after a shared failure — producing a "thundering herd" load pattern. Prefer DecorrelatedJitter unless you specifically need deterministic delays.
Instance Method Summary collapse
-
#delay_for(attempt) ⇒ Float
Delay seconds (capped).
-
#initialize(base:, cap:, factor: DEFAULT_FACTOR) ⇒ Exponential
constructor
A new instance of Exponential.
Constructor Details
#initialize(base:, cap:, factor: DEFAULT_FACTOR) ⇒ Exponential
Returns a new instance of Exponential.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tenax/retry/backoff/exponential.rb', line 33 def initialize(base:, cap:, factor: DEFAULT_FACTOR) raise ArgumentError, "base must be positive, got #{base}" if base <= 0 raise ArgumentError, "cap must be positive, got #{cap}" if cap <= 0 raise ArgumentError, "factor must be > 1, got #{factor}" if factor <= 1 raise ArgumentError, "cap must be >= base, got base=#{base}, cap=#{cap}" if cap < base super() @base = base.to_f @cap = cap.to_f @factor = factor.to_f freeze end |
Instance Method Details
#delay_for(attempt) ⇒ Float
Returns delay seconds (capped).
48 49 50 51 52 53 |
# File 'lib/tenax/retry/backoff/exponential.rb', line 48 def delay_for(attempt) raise ArgumentError, "attempt must be >= 1, got #{attempt}" if attempt < 1 delay = @base * (@factor**(attempt - 1)) [delay, @cap].min end |