#include <userver/utils/aimd_limiter.hpp>
Thread safe AIMD (Additive Increase Multiplicative Decrease) limiter.
Keeps an adaptive limit within [min_limit, max_limit]:
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 | |
| AimdLimiter & | operator= (const AimdLimiter &)=delete |
| AimdLimiter & | operator= (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. | |
| utils::AimdLimiter::AimdLimiter | ( | std::size_t | max_limit, |
| Policy | policy ) |
Create a limiter with the current limit set to max_limit
| std::runtime_error | if the policy is invalid |
| void utils::AimdLimiter::SetPolicy | ( | Policy | policy | ) |
Set limit update policy
| std::runtime_error | if the policy is invalid |