Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff interface {
// Attempt returns the n-th backoff duration.
// Used algorithm depends on implementers.
// Returned duration can be zero or positive.
Attempt(attempt int) time.Duration
}
Backoff provides backoff algorithm.
type BackoffError ¶
BackoffError reports errors in backoff.
func (*BackoffError) Error ¶
func (e *BackoffError) Error() string
func (*BackoffError) Is ¶
func (e *BackoffError) Is(target error) bool
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
ExponentialBackoff provides exponential backoff strategy. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for exponential function. (>=0) fluctuation: value range of fluctuation part. (>=0) Input: attempt : the count of attempts. Output: Calculate fluctuation value flc := (coeff * 2^attempt) If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + flc Return bod. Value range: Min: offset Max: offset + fluctuation
Graph:
y:backoff
|
offset|------------────────────────────
+ | /
fluc. | / y=offset+coeff*2^x
| /
| /
| /
offset|──/----------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewExponentialBackoff ¶
func NewExponentialBackoff(offset, fluctuation, coeff time.Duration) *ExponentialBackoff
NewExponentialBackoff returns a new instance of ExponentialBackoff. See comments on the ExponentialBackoff for details. Allowed value range is offset>=0, fluctuation>=0, coeff>=0, otherwise it panics.
type ExponentialBackoffEqualJitter ¶
type ExponentialBackoffEqualJitter struct {
// contains filtered or unexported fields
}
ExponentialBackoffEqualJitter provides exponential backoff strategy with equal jitter. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for exponential function. (>0) fluctuation: value range of fluctuation part. (>0) Input: attempt : the count of attempts. Output: Calculate fluctuation value flc := (coeff * 2^attempt) If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + (flc/2 + RandomRange(0,flc/2)) Return bod. Value range: Min: offset Max: offset + fluctuation
Graph:
y:backoff
| y=offset+coeff*2^x
offset|------------────────────────────
+ | ////////// ↑ /////////
fluc. | /////////// ↓ random //
| ////────────────────────
| ///
| ///
offset|──/----------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewExponentialBackoffEqualJitter ¶
func NewExponentialBackoffEqualJitter(offset, fluctuation, coeff time.Duration) *ExponentialBackoffEqualJitter
NewExponentialBackoffEqualJitter returns a new instance of ExponentialBackoffEqualJitter. See comments on the ExponentialBackoffEqualJitter for details. Allowed value range is offset>=0, fluctuation>0, coeff>0, otherwise it panics.
type ExponentialBackoffFullJitter ¶
type ExponentialBackoffFullJitter struct {
// contains filtered or unexported fields
}
ExponentialBackoffFullJitter provides exponential backoff strategy with full jitter. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for exponential function. (>0) fluctuation: value range of fluctuation part. (>0) Input: attempt : the count of attempts. Output: Calculate fluctuation value flc := (coeff * 2^attempt) If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + RandomRange(0,flc) Return bod. Value range: Min: offset Max: offset + fluctuation
Graph:
y:backoff
| y=offset+coeff*2^x
offset|------------────────────────────
+ | ////////// ↑ /////////
fluc. | /////////// | /////////
| //////////// | random //
| ///////////// | /////////
| /////////////// ↓ /////////
offset|──/----------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewExponentialBackoffFullJitter ¶
func NewExponentialBackoffFullJitter(offset, fluctuation, coeff time.Duration) *ExponentialBackoffFullJitter
NewExponentialBackoffFullJitter returns a new instance of ExponentialBackoffFullJitter. See comments on the ExponentialBackoffFullJitter for details. Allowed value range is offset>=0, fluctuation>0, coeff>0, otherwise it panics.
type FibonacciBackoff ¶
type FibonacciBackoff struct {
// contains filtered or unexported fields
}
FibonacciBackoff provides backoff strategy using fibonacci sequence. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for fibonacci number. (>=0) fluctuation: value range of fluctuation part. (>=0) Input: attempt : the count of attempts. Output: Calculate fluctuation value flc := coeff * fibonacci(attempt). If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + flc Return bod. Value range: Min: offset Max: offset + fluctuation Limitations: The "attempt" must be attempt<=46. If exceeded, 46 is used.
func NewFibonacciBackoff ¶
func NewFibonacciBackoff(offset, fluctuation, coeff time.Duration) *FibonacciBackoff
NewFibonacciBackoff returns a new instance of FibonacciBackoff. See comments on the FibonacciBackoff for details. Allowed value range is offset>=0, fluctuation>=0, coeff>=0, otherwise it panics.
type FixedBackoff ¶
type FixedBackoff struct {
// contains filtered or unexported fields
}
FixedBackoff provides fixed interval backoff strategy.
Algorithm:
Parameter: value: fixed duration. (>=0) Input: attempt: the count of attempts. Output: Always return the value. Value range: Min: value Max: value
Graph:
y:backoff
|
|
|
| y=value
value|-------------------------------
|
|
|
|
└─────────────────────────────── x:attempts
0
func NewFixedBackoff ¶
func NewFixedBackoff(value time.Duration) *FixedBackoff
NewFixedBackoff returns a new instance of FixedBackoff. See comments on the FixedBackoff for details. Allowed value range is value>=0, otherwise it panics.
type LinearBackoff ¶
type LinearBackoff struct {
// contains filtered or unexported fields
}
LinearBackoff provides fixed backoff strategy. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for linear function. (>=0) fluctuation: value range of fluctuation part. (>=0) Input: attempt : the count of attempts. Output: Calculate fluctuation value flc := (coeff * attempt) If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + flc Return bod. Value range: Min: offset Max: offset + fluctuation
Graph:
y:backoff
|
offset|------------───────────────────
+ | /
fluc. | /
| / y=offset+coeff*x
| /
| /
offset|-------------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewLinearBackoff ¶
func NewLinearBackoff(offset, fluctuation, coeff time.Duration) *LinearBackoff
NewLinearBackoff returns a new instance of LinearBackoff. See comments on the LinearBackoff for details. Allowed value range is offset>=0, fluctuation>=0, coeff>=0, otherwise it panics.
type PolynomialBackoff ¶
type PolynomialBackoff struct {
// contains filtered or unexported fields
}
PolynomialBackoff provides polynomial backoff strategy. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset duration. (>=0) coeff: coefficient for polynomial function. (>=0) fluctuation: value range of fluctuation part. (>=0) exponent: exponent value for exponential function. Input: attempt : the count of attempts. (>0) Output: Calculate fluctuation value flc := (coeff * attempt^exponent) If flc > fluctuation, then let flc fluctuation. Calculate backoff duration bod := offset + flc Return bod. Value range: Min: offset Max: offset + fluctuation Limitations: The "attempt" must be attempt>0. If not, 1 is used.
Graph:
y:backoff
|
offset|------------────────────────────
+ | /
fluc. | / y=offset+coeff*x^exponent
| /
| /
| /
offset|──/----------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewPolynomialBackoff ¶
func NewPolynomialBackoff(offset, fluctuation, coeff time.Duration, exponent float64) *PolynomialBackoff
NewPolynomialBackoff returns a new instance of PolynomialBackoff. See comments on the PolynomialBackoff for details. Allowed value range is offset>=0, fluctuation>=0, coeff>=0, otherwise it panics.
type RandomBackoff ¶
type RandomBackoff struct {
// contains filtered or unexported fields
}
RandomBackoff provides random backoff strategy. It will panic if the parameter range is not satisfied.
Algorithm:
Parameter: offset: offset of the backoff duration. (>=0) fluctuation: backoff fluctuation range. (>0) Input: attempt: the count of attempts. Output: Calculate backoff duration bod := offset + RandomRange(0, fluctuation) Return bod. Value range: Min: offset Max: offset + fluctuation
Graph:
y:backoff
|
offset|-------------------------------
+ | /\ /──\
fluc. | / | /| | | /\ y=offset+random(fluc)
| / | | \ | \ / \
| / |/ \ / \/ \
| / \/ \
offset|-------------------------------
|
|
└─────────────────────────────── x:attempts
0
func NewRandomBackoff ¶
func NewRandomBackoff(offset, fluctuation time.Duration) *RandomBackoff
NewRandomBackoff returns a new instance of RandomBackoff. See comments on the RandomBackoff for details. Allowed value range is offset>=0, fluctuation>0, otherwise it panics.