userver: utils::AimdLimiter Class Reference
Loading...
Searching...
No Matches
utils::AimdLimiter Class Referencefinal

#include <userver/utils/aimd_limiter.hpp>

Detailed Description

Thread safe AIMD (Additive Increase Multiplicative Decrease) limiter.

Keeps an adaptive limit within [min_limit, max_limit]:

  • on success the limit is additively increased: limit = min(max_limit, limit + alpha / limit);
  • on failure the limit is multiplicatively decreased: limit = max(min_limit, limit * beta).

If max_limit is set below Policy::min_limit, max_limit wins and GetCurrentLimit() returns max_limit.

Definition at line 26 of file aimd_limiter.hpp.

Classes

struct  Policy
 AIMD limit update policy. More...

Public Member Functions

 AimdLimiter (std::size_t max_limit, Policy policy)
 AimdLimiter (const AimdLimiter &)=delete
 AimdLimiter (AimdLimiter &&)=delete
AimdLimiteroperator= (const AimdLimiter &)=delete
AimdLimiteroperator= (AimdLimiter &&)=delete
void SetMaxLimit (std::size_t max_limit) noexcept
 Set the upper bound for the limit, clamping down the current limit if needed.
void SetPolicy (Policy policy)
std::size_t GetMaxLimit () const noexcept
 Get the upper bound for the limit (might be inaccurate as the result is stale).
std::size_t GetCurrentLimit () const noexcept
 Get current limit (might be inaccurate as the result is stale).
void OnSuccess () noexcept
 Additively increase the limit up to the max limit.
void OnFailure () noexcept
 Multiplicatively decrease the limit down to the min limit.

Constructor & Destructor Documentation

◆ AimdLimiter()

utils::AimdLimiter::AimdLimiter ( std::size_t max_limit,
Policy policy )

Create a limiter with the current limit set to max_limit

Exceptions
std::runtime_errorif the policy is invalid

Member Function Documentation

◆ SetPolicy()

void utils::AimdLimiter::SetPolicy ( Policy policy)

Set limit update policy

Exceptions
std::runtime_errorif the policy is invalid

The documentation for this class was generated from the following file: