proxygen
|
#include <Codel.h>
Public Member Functions | |
Codel () | |
bool | overloaded (std::chrono::nanoseconds delay) |
int | getLoad () |
std::chrono::nanoseconds | getMinDelay () |
std::chrono::milliseconds | getInterval () |
std::chrono::milliseconds | getTargetDelay () |
std::chrono::milliseconds | getSloughTimeout () |
Private Attributes | |
std::atomic< uint64_t > | codelMinDelayNs_ |
std::atomic< uint64_t > | codelIntervalTimeNs_ |
std::atomic< bool > | codelResetDelay_ |
std::atomic< bool > | overloaded_ |
CoDel (controlled delay) is an active queue management algorithm from networking for battling bufferbloat.
Services also have queues (of requests, not packets) and suffer from queueing delay when overloaded. This class adapts the codel algorithm for services.
Codel is discussed in depth on the web [1,2], but a basic sketch of the algorithm is this: if every request has experienced queueing delay greater than the target (5ms) during the past interval (100ms), then we shed load.
We have adapted the codel algorithm. TCP sheds load by changing windows in reaction to dropped packets. Codel in a network setting drops packets at increasingly shorter intervals (100 / sqrt(n)) to achieve a linear change in throughput. In our experience a different scheme works better for services: when overloaded slough off requests that we dequeue which have exceeded an alternate timeout (2 * target_delay).
So in summary, to use this class, calculate the time each request spent in the queue and feed that delay to overloaded(), which will tell you whether to expire this request.
You can also ask for an instantaneous load estimate and the minimum delay observed during this interval.
folly::Codel::Codel | ( | ) |
Definition at line 29 of file Codel.cpp.
milliseconds folly::Codel::getInterval | ( | ) |
Definition at line 93 of file Codel.cpp.
Referenced by overloaded().
int folly::Codel::getLoad | ( | ) |
Get the queue load, as seen by the codel algorithm Gives a rough guess at how bad the queue delay is.
min(100%, min_delay / (2 * target_delay))
Return: 0 = no delay, 100 = At the queueing limit
Definition at line 83 of file Codel.cpp.
References getMinDelay(), and getSloughTimeout().
Referenced by TEST().
nanoseconds folly::Codel::getMinDelay | ( | ) |
milliseconds folly::Codel::getSloughTimeout | ( | ) |
Definition at line 101 of file Codel.cpp.
References getTargetDelay().
Referenced by getLoad(), and overloaded().
milliseconds folly::Codel::getTargetDelay | ( | ) |
Definition at line 97 of file Codel.cpp.
Referenced by getSloughTimeout(), and overloaded().
bool folly::Codel::overloaded | ( | std::chrono::nanoseconds | delay | ) |
Returns true if this request should be expired to reduce overload. In detail, this returns true if min_delay > target_delay for the interval, and this delay > 2 * target_delay.
As you may guess, we observe the clock so this is time sensitive. Call it promptly after calculating queueing delay.
Definition at line 37 of file Codel.cpp.
References codelIntervalTimeNs_, codelMinDelayNs_, codelResetDelay_, count, getInterval(), getSloughTimeout(), getTargetDelay(), now(), and overloaded_.
Referenced by TEST().
|
private |
Definition at line 84 of file Codel.h.
Referenced by overloaded().
|
private |
Definition at line 83 of file Codel.h.
Referenced by getMinDelay(), and overloaded().
|
private |
Definition at line 88 of file Codel.h.
Referenced by overloaded().
|
private |
Definition at line 90 of file Codel.h.
Referenced by overloaded().