LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Private Attributes
LogCabin::Client::Backoff Class Reference

A simple backoff mechanism. More...

#include <Backoff.h>

List of all members.

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< TimePointstartTimes
 The times when the last windowCount operations were initiated.

Detailed Description

A simple backoff mechanism.

Currently used in the client library to rate-limit the creation of new TCP connections.

Definition at line 32 of file Backoff.h.


Member Typedef Documentation

Clock used for keeping track of when operations started.

Definition at line 35 of file Backoff.h.

Point in time on Clock. Used for timeouts.

Definition at line 37 of file Backoff.h.


Constructor & Destructor Documentation

LogCabin::Client::Backoff::Backoff ( uint64_t  windowCount,
uint64_t  windowNanos 
)

Constructor.

Parameters:
windowCountAt most this many operations are allowed in any windowNanos period of time.
windowNanosThe duration over which at most windowCount operations are allowed.
Warning:
The memory usage of this class is proportional to windowCount.

Definition at line 21 of file Backoff.cc.

Destructor.

Definition at line 31 of file Backoff.cc.


Member Function Documentation

This is invoked before beginning a new operation.

If the operation may not proceed yet, this method sleeps until starting the operation becomes permissible.

Parameters:
timeoutMaximum time at which to stop sleeping and return, without marking the operation as having started.

Definition at line 36 of file Backoff.cc.


Member Data Documentation

std::mutex LogCabin::Client::Backoff::mutex [private]

Protects all of the following member variables in this class.

Definition at line 71 of file Backoff.h.

At most windowCount operations are allowed in any windowDuration period of time.

Definition at line 77 of file Backoff.h.

std::chrono::nanoseconds LogCabin::Client::Backoff::windowDuration [private]

See windowCount.

Definition at line 82 of file Backoff.h.

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.

Definition at line 90 of file Backoff.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines