AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
AdaptiveRetryStrategy.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/client/RetryStrategy.h>
10#include <aws/core/utils/DateTime.h>
11
12namespace Aws
13{
14namespace Client
15{
16
21class AWS_CORE_API RetryTokenBucket
22{
23public:
27 RetryTokenBucket() = default;
28
35 bool Acquire(size_t amount = 1, bool fastFail = false);
36
41 void UpdateClientSendingRate(bool throttlingResponse, const Aws::Utils::DateTime& now = Aws::Utils::DateTime::Now());
42
43protected:
47 RetryTokenBucket(double fillRate, double maxCapacity, double currentCapacity,
48 const Aws::Utils::DateTime& lastTimestamp, double measuredTxRate, double lastTxRateBucket,
49 size_t requestCount, bool enabled, double lastMaxRate, const Aws::Utils::DateTime& lastThrottleTime);
50
58
62 void Enable();
63
67 void UpdateRate(double newRps, const Aws::Utils::DateTime& now = Aws::Utils::DateTime::Now());
68
73
77 double CalculateTimeWindow() const;
78
82 double CUBICSuccess(const Aws::Utils::DateTime& timestamp, const double timeWindow) const;
83
87 double CUBICThrottle(const double rateToUse) const;
88
89 // The rate at which token are replenished.
90 double m_fillRate = 0.0;
91 // The maximum capacity allowed in the token bucket.
92 double m_maxCapacity = 0.0;
93 // The current capacity of the token bucket.
94 double m_currentCapacity = 0.0;
95 // The last time the token bucket was refilled.
97 // The smoothed rate which tokens are being retrieved.
98 double m_measuredTxRate = 0.0;
99 // The last half second time bucket used.
100 double m_lastTxRateBucket = 0.0;
101 // The number of requests seen within the current time bucket.
102 size_t m_requestCount = 0;
103 // Boolean indicating if the token bucket is enabled.
104 bool m_enabled = false;
105 // The maximum rate when the client was last throttled.
106 double m_lastMaxRate = 0.0;
107 // The last time when the client was throttled.
109
110 // TokenBucket's mutex to synchronize read/write operations
111 std::recursive_mutex m_mutex;
112};
113
119{
120public:
124 AdaptiveRetryStrategy(long maxAttempts = 3);
125 AdaptiveRetryStrategy(std::shared_ptr<RetryQuotaContainer> retryQuotaContainer, long maxAttempts = 3);
126
134 virtual bool HasSendToken() override;
135
139 virtual void RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome) override;
140 virtual void RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome, const AWSError<CoreErrors>& lastError) override;
141
142 const char* GetStrategyName() const override { return "adaptive";}
143
144protected:
146 bool m_fastFail = false;
147
148private:
152 static bool IsThrottlingResponse(const HttpResponseOutcome& httpResponseOutcome);
153};
154
155} // namespace Client
156} // namespace Aws
virtual bool HasSendToken() override
AdaptiveRetryStrategy(long maxAttempts=3)
AdaptiveRetryStrategy(std::shared_ptr< RetryQuotaContainer > retryQuotaContainer, long maxAttempts=3)
const char * GetStrategyName() const override
virtual void RequestBookkeeping(const HttpResponseOutcome &httpResponseOutcome) override
virtual void RequestBookkeeping(const HttpResponseOutcome &httpResponseOutcome, const AWSError< CoreErrors > &lastError) override
void UpdateMeasuredRate(const Aws::Utils::DateTime &now=Aws::Utils::DateTime::Now())
void Refill(const Aws::Utils::DateTime &now=Aws::Utils::DateTime::Now())
double CUBICSuccess(const Aws::Utils::DateTime &timestamp, const double timeWindow) const
bool Acquire(size_t amount=1, bool fastFail=false)
void UpdateClientSendingRate(bool throttlingResponse, const Aws::Utils::DateTime &now=Aws::Utils::DateTime::Now())
RetryTokenBucket(double fillRate, double maxCapacity, double currentCapacity, const Aws::Utils::DateTime &lastTimestamp, double measuredTxRate, double lastTxRateBucket, size_t requestCount, bool enabled, double lastMaxRate, const Aws::Utils::DateTime &lastThrottleTime)
double CalculateTimeWindow() const
void UpdateRate(double newRps, const Aws::Utils::DateTime &now=Aws::Utils::DateTime::Now())
double CUBICThrottle(const double rateToUse) const
static DateTime Now()