LogCabin
|
A simple backoff mechanism. More...
#include <Backoff.h>
Public Types | |
typedef Core::Time::SteadyClock | Clock |
Clock used for keeping track of when operations started. | |
typedef Clock::time_point | TimePoint |
Point in time on Clock. Used for timeouts. | |
Public Member Functions | |
Backoff (uint64_t windowCount, uint64_t windowNanos) | |
Constructor. | |
~Backoff () | |
Destructor. | |
void | delayAndBegin (TimePoint timeout) |
This is invoked before beginning a new operation. | |
Private Attributes | |
std::mutex | mutex |
Protects all of the following member variables in this class. | |
uint64_t | windowCount |
At most windowCount operations are allowed in any windowDuration period of time. | |
std::chrono::nanoseconds | windowDuration |
See windowCount. | |
std::deque< TimePoint > | startTimes |
The times when the last windowCount operations were initiated. |
A simple backoff mechanism.
Currently used in the client library to rate-limit the creation of new TCP connections.
LogCabin::Client::Backoff::Backoff | ( | uint64_t | windowCount, |
uint64_t | windowNanos | ||
) |
Constructor.
windowCount | At most this many operations are allowed in any windowNanos period of time. |
windowNanos | The duration over which at most windowCount operations are allowed. |
Definition at line 21 of file Backoff.cc.
Destructor.
Definition at line 31 of file Backoff.cc.
void LogCabin::Client::Backoff::delayAndBegin | ( | TimePoint | timeout | ) |
This is invoked before beginning a new operation.
If the operation may not proceed yet, this method sleeps until starting the operation becomes permissible.
timeout | Maximum time at which to stop sleeping and return, without marking the operation as having started. |
Definition at line 36 of file Backoff.cc.
std::mutex LogCabin::Client::Backoff::mutex [private] |
uint64_t LogCabin::Client::Backoff::windowCount [private] |
At most windowCount operations are allowed in any windowDuration period of time.
std::chrono::nanoseconds LogCabin::Client::Backoff::windowDuration [private] |
See windowCount.
std::deque<TimePoint> LogCabin::Client::Backoff::startTimes [private] |
The times when the last windowCount operations were initiated.
If fewer than windowCount operations have been initiated, this is padded with negative infinity. The front time is the oldest, and the back is the most recent.