diff options
author | hor911 <hor911@ydb.tech> | 2023-02-09 12:40:11 +0300 |
---|---|---|
committer | hor911 <hor911@ydb.tech> | 2023-02-09 12:40:11 +0300 |
commit | 24689527cd888aa8a640ecb5077e656b3520d373 (patch) | |
tree | a613ff4cd9567b7113e8376a17f8b85897a42790 /library/cpp/unified_agent_client/throttling.h | |
parent | 8642d3642932f03663ba7d2d9670707c192207fd (diff) | |
download | ydb-24689527cd888aa8a640ecb5077e656b3520d373.tar.gz |
Log backend move
Diffstat (limited to 'library/cpp/unified_agent_client/throttling.h')
-rw-r--r-- | library/cpp/unified_agent_client/throttling.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/library/cpp/unified_agent_client/throttling.h b/library/cpp/unified_agent_client/throttling.h new file mode 100644 index 0000000000..1e5db1e8fa --- /dev/null +++ b/library/cpp/unified_agent_client/throttling.h @@ -0,0 +1,30 @@ +#pragma once + +#include <library/cpp/unified_agent_client/f_maybe.h> + +#include <util/datetime/base.h> + +namespace NUnifiedAgent { + class TThrottler { + public: + explicit TThrottler(double rate, TDuration updatePeriod = TDuration::MilliSeconds(100)); + + TThrottler(double rate, double burst); + + void Consume(double& tokens, TFMaybe<TDuration>& nextCheckDelay); + + bool TryConsume(double tokens); + + void ConsumeAndWait(double tokens); + + private: + ui64 UpdateTokens(); + + private: + ui64 CyclesPerMillisecond; + ui64 UpdatePeriod; + double PeriodTokens; + double AvailableTokens; + ui64 ExpirationTime; + }; +} |