Module: Mongo::Retryable::Backpressure Private

Defined in:
lib/mongo/retryable/backpressure.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constants and helpers for client backpressure (exponential backoff and jitter in retry loops).

Since:

  • 2.1.0

Constant Summary collapse

BASE_BACKOFF =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Base backoff delay in seconds.

Since:

  • 2.1.0

0.1
MAX_BACKOFF =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Maximum backoff delay in seconds.

Since:

  • 2.1.0

10
DEFAULT_MAX_RETRIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default maximum number of retries for overload errors.

Since:

  • 2.1.0

2

Class Method Summary collapse

Class Method Details

.backoff_delay(attempt, jitter: rand) ⇒ Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculate the backoff delay for a given retry attempt.

Parameters:

  • attempt (Integer)

    The retry attempt number (1-indexed).

  • jitter (Float) (defaults to: rand)

    A random float in [0.0, 1.0). Defaults to a random value. Can be injected for deterministic testing.

Returns:

  • (Float)

    The backoff delay in seconds.

Since:

  • 2.1.0



26
27
28
# File 'lib/mongo/retryable/backpressure.rb', line 26

def self.backoff_delay(attempt, jitter: rand)
  jitter * [ MAX_BACKOFF, BASE_BACKOFF * (2**(attempt - 1)) ].min
end