proxygen
wangle::LoadShedConfiguration Class Reference

#include <LoadShedConfiguration.h>

Classes

struct  AddressOnlyCompare
 
struct  SysParams
 

Public Types

typedef std::set< folly::SocketAddress, AddressOnlyCompareAddressSet
 
typedef std::set< NetworkAddressNetworkSet
 

Public Member Functions

 LoadShedConfiguration ()=default
 
 ~LoadShedConfiguration ()=default
 
void addWhitelistAddr (folly::StringPiece)
 
void setWhitelistAddrs (const AddressSet &addrs)
 
const AddressSetgetWhitelistAddrs () const
 
void setWhitelistNetworks (const NetworkSet &networks)
 
const NetworkSetgetWhitelistNetworks () const
 
void setMaxConnections (uint64_t maxConns)
 
uint64_t getMaxConnections () const
 
void setMaxActiveConnections (uint64_t maxActiveConns)
 
uint64_t getMaxActiveConnections () const
 
void setAcceptPauseOnAcceptorQueueSize (const uint64_t acceptPauseOnAcceptorQueueSize)
 
uint64_t getAcceptPauseOnAcceptorQueueSize () const
 
void setAcceptResumeOnAcceptorQueueSize (const uint64_t acceptResumeOnAcceptorQueueSize)
 
uint64_t getAcceptResumeOnAcceptorQueueSize () const
 
void setMaxMemUsage (double max)
 
double getMaxMemUsage () const
 
void setMaxCpuUsage (double max)
 
double getMaxCpuUsage () const
 
void setMinCpuIdle (double min)
 
double getMinCpuIdle () const
 
void setLogicalCpuCoreQuorum (uint64_t quorum)
 
uint64_t getLogicalCpuCoreQuorum () const
 
void setCpuUsageExceedWindowSize (const uint64_t size)
 
uint64_t getCpuUsageExceedWindowSize () const
 
void setMinFreeMem (uint64_t min)
 
uint64_t getMinFreeMem () const
 
void setLoadUpdatePeriod (std::chrono::milliseconds period)
 
std::chrono::milliseconds getLoadUpdatePeriod () const
 
void setMaxTcpMemUsage (double max)
 
double getMaxTcpMemUsage () const
 
void setMinFreeTcpMemPct (double min)
 
double getMinFreeTcpMemPct () const
 
void setLoadSheddingEnabled (bool enabled)
 
bool getLoadSheddingEnabled () const
 
bool isWhitelisted (const folly::SocketAddress &addr) const
 
void checkIsSane (const SysParams &sysParams) const
 

Private Attributes

AddressSet whitelistAddrs_
 
NetworkSet whitelistNetworks_
 
uint64_t maxConnections_ {0}
 
uint64_t maxActiveConnections_ {0}
 
uint64_t acceptPauseOnAcceptorQueueSize_ {0}
 
uint64_t acceptResumeOnAcceptorQueueSize_ {0}
 
uint64_t minFreeMem_ {0}
 
double maxMemUsage_ {1.0}
 
double maxCpuUsage_ {1.0}
 
double minCpuIdle_ {0.0}
 
uint64_t logicalCpuCoreQuorum_ {0}
 
uint64_t cpuUsageExceedWindowSize_ {0}
 
double maxTcpMemUsage_ {1.0}
 
double minFreeTcpMemPct_ {0.0}
 
std::chrono::milliseconds period_
 
bool loadSheddingEnabled_ {true}
 

Detailed Description

Class that holds an LoadShed configuration for a service

Definition at line 33 of file LoadShedConfiguration.h.

Member Typedef Documentation

Constructor & Destructor Documentation

wangle::LoadShedConfiguration::LoadShedConfiguration ( )
default
wangle::LoadShedConfiguration::~LoadShedConfiguration ( )
default

Member Function Documentation

void wangle::LoadShedConfiguration::addWhitelistAddr ( folly::StringPiece  input)

Definition at line 26 of file LoadShedConfiguration.cpp.

References addr, folly::Range< Iter >::str(), whitelistAddrs_, and whitelistNetworks_.

Referenced by TEST().

26  {
27  auto addr = input.str();
28  size_t separator = addr.find_first_of('/');
29  if (separator == string::npos) {
31  } else {
32  unsigned prefixLen = folly::to<unsigned>(addr.substr(separator + 1));
33  addr.erase(separator);
34  whitelistNetworks_.insert(
35  NetworkAddress(SocketAddress(addr, 0), prefixLen));
36  }
37 }
std::string str() const
Definition: Range.h:591
ThreadPoolListHook * addr
void wangle::LoadShedConfiguration::checkIsSane ( const SysParams sysParams) const

Definition at line 51 of file LoadShedConfiguration.cpp.

References cpuUsageExceedWindowSize_, loadSheddingEnabled_, logicalCpuCoreQuorum_, maxActiveConnections_, maxConnections_, maxCpuUsage_, maxMemUsage_, maxTcpMemUsage_, minCpuIdle_, minFreeMem_, minFreeTcpMemPct_, wangle::LoadShedConfiguration::SysParams::numLogicalCpuCores, period_, and wangle::LoadShedConfiguration::SysParams::totalMemBytes.

51  {
53  // Period must be greater than or equal to 0.
54  CHECK_GE(period_.count(), std::chrono::milliseconds(0).count());
55 
56  // CPU exceed window must be of size at least equal to 1.
57  CHECK_GE(cpuUsageExceedWindowSize_, 1);
58 
59  // Min cpu idle and max cpu ratios must have values in the range of [0-1]
60  // inclusive and min cpu idle, normalized, must be greater than or equal
61  // to max cpu ratio.
62  CHECK_GE(minCpuIdle_, 0.0);
63  CHECK_LE(minCpuIdle_, 1.0);
64  CHECK_GE(1.0 - minCpuIdle_, maxCpuUsage_);
65  CHECK_GE(maxCpuUsage_, 0.0);
66  CHECK_LE(maxCpuUsage_, 1.0);
67  CHECK_GE(logicalCpuCoreQuorum_, 0);
68  CHECK_LE(logicalCpuCoreQuorum_, sysParams.numLogicalCpuCores);
69 
70  // Max mem usage must be less than or equal to min free mem, normalized.
71  // We also must verify that min free mem is less than or equal to total
72  // mem bytes.
73  CHECK_GE(maxMemUsage_, 0.0);
74  CHECK_LE(maxMemUsage_, 1.0);
75  CHECK_GE(
76  1.0 - ((double)minFreeMem_ / sysParams.totalMemBytes), maxMemUsage_);
77  CHECK_LE(minFreeMem_, sysParams.totalMemBytes);
78 
79  // Max TCP mem and min free TCP mem ratios must have values in the range
80  // of [0-1] inclusive and 1.0 minus min TCP mem ration must be greater than
81  // or equal to max TCP mem ratio.
82  CHECK_GE(maxTcpMemUsage_, 0.0);
83  CHECK_LE(maxTcpMemUsage_, 1.0);
84  CHECK_GE(1.0 - minFreeTcpMemPct_, maxTcpMemUsage_);
85  CHECK_GE(minFreeTcpMemPct_, 0.0);
86  CHECK_LE(minFreeTcpMemPct_, 1.0);
87 
88  // Active connetions obviously must be less than or equal to max
89  // connections.
91  }
92 }
std::chrono::milliseconds period_
uint64_t wangle::LoadShedConfiguration::getAcceptPauseOnAcceptorQueueSize ( ) const
inline

Definition at line 93 of file LoadShedConfiguration.h.

References acceptPauseOnAcceptorQueueSize_.

Referenced by TEST().

93  {
95  }
uint64_t wangle::LoadShedConfiguration::getAcceptResumeOnAcceptorQueueSize ( ) const
inline

Definition at line 105 of file LoadShedConfiguration.h.

References acceptResumeOnAcceptorQueueSize_.

Referenced by TEST().

105  {
107  }
uint64_t wangle::LoadShedConfiguration::getCpuUsageExceedWindowSize ( ) const
inline

Definition at line 167 of file LoadShedConfiguration.h.

References cpuUsageExceedWindowSize_.

Referenced by TEST().

167  {
169  }
bool wangle::LoadShedConfiguration::getLoadSheddingEnabled ( ) const
inline

Definition at line 210 of file LoadShedConfiguration.h.

References addr, isWhitelisted(), and loadSheddingEnabled_.

210  {
211  return loadSheddingEnabled_;
212  }
std::chrono::milliseconds wangle::LoadShedConfiguration::getLoadUpdatePeriod ( ) const
inline

Definition at line 186 of file LoadShedConfiguration.h.

References period_.

Referenced by TEST().

186 { return period_; }
std::chrono::milliseconds period_
uint64_t wangle::LoadShedConfiguration::getLogicalCpuCoreQuorum ( ) const
inline

Definition at line 156 of file LoadShedConfiguration.h.

References logicalCpuCoreQuorum_.

156  {
157  return logicalCpuCoreQuorum_;
158  }
uint64_t wangle::LoadShedConfiguration::getMaxActiveConnections ( ) const
inline

Definition at line 83 of file LoadShedConfiguration.h.

References maxActiveConnections_.

Referenced by TEST().

uint64_t wangle::LoadShedConfiguration::getMaxConnections ( ) const
inline

Definition at line 74 of file LoadShedConfiguration.h.

References maxConnections_.

Referenced by TEST().

double wangle::LoadShedConfiguration::getMaxCpuUsage ( ) const
inline

Definition at line 131 of file LoadShedConfiguration.h.

References maxCpuUsage_.

Referenced by TEST().

double wangle::LoadShedConfiguration::getMaxMemUsage ( ) const
inline

Definition at line 119 of file LoadShedConfiguration.h.

References maxMemUsage_.

Referenced by TEST().

double wangle::LoadShedConfiguration::getMaxTcpMemUsage ( ) const
inline

Definition at line 193 of file LoadShedConfiguration.h.

References maxTcpMemUsage_.

193  {
194  return maxTcpMemUsage_;
195  }
double wangle::LoadShedConfiguration::getMinCpuIdle ( ) const
inline

Definition at line 143 of file LoadShedConfiguration.h.

References minCpuIdle_.

Referenced by TEST().

uint64_t wangle::LoadShedConfiguration::getMinFreeMem ( ) const
inline

Definition at line 179 of file LoadShedConfiguration.h.

References minFreeMem_.

Referenced by TEST().

179  {
180  return minFreeMem_;
181  }
double wangle::LoadShedConfiguration::getMinFreeTcpMemPct ( ) const
inline

Definition at line 202 of file LoadShedConfiguration.h.

References minFreeTcpMemPct_.

202  {
203  return minFreeTcpMemPct_;
204  }
const AddressSet& wangle::LoadShedConfiguration::getWhitelistAddrs ( ) const
inline

Definition at line 59 of file LoadShedConfiguration.h.

References whitelistAddrs_.

Referenced by TEST().

const NetworkSet& wangle::LoadShedConfiguration::getWhitelistNetworks ( ) const
inline

Definition at line 68 of file LoadShedConfiguration.h.

References whitelistNetworks_.

Referenced by TEST().

bool wangle::LoadShedConfiguration::isWhitelisted ( const folly::SocketAddress addr) const

Definition at line 39 of file LoadShedConfiguration.cpp.

References whitelistAddrs_, and whitelistNetworks_.

Referenced by getLoadSheddingEnabled(), and TEST().

39  {
40  if (whitelistAddrs_.find(address) != whitelistAddrs_.end()) {
41  return true;
42  }
43  for (auto& network : whitelistNetworks_) {
44  if (network.contains(address)) {
45  return true;
46  }
47  }
48  return false;
49 }
void wangle::LoadShedConfiguration::setAcceptPauseOnAcceptorQueueSize ( const uint64_t  acceptPauseOnAcceptorQueueSize)
inline

Set/get the acceptor queue size which can be used to pause accepting new client connections.

Definition at line 89 of file LoadShedConfiguration.h.

References acceptPauseOnAcceptorQueueSize_.

Referenced by TEST().

90  {
91  acceptPauseOnAcceptorQueueSize_ = acceptPauseOnAcceptorQueueSize;
92  }
void wangle::LoadShedConfiguration::setAcceptResumeOnAcceptorQueueSize ( const uint64_t  acceptResumeOnAcceptorQueueSize)
inline

Set/get the acceptor queue size which can be used to resume accepting new client connections if accepting is paused.

Definition at line 101 of file LoadShedConfiguration.h.

References acceptResumeOnAcceptorQueueSize_.

Referenced by TEST().

102  {
103  acceptResumeOnAcceptorQueueSize_ = acceptResumeOnAcceptorQueueSize;
104  }
void wangle::LoadShedConfiguration::setCpuUsageExceedWindowSize ( const uint64_t  size)
inline

Set/get the CPU usage exceed window size

Definition at line 163 of file LoadShedConfiguration.h.

References cpuUsageExceedWindowSize_, and folly::size().

Referenced by TEST().

163  {
165  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void wangle::LoadShedConfiguration::setLoadSheddingEnabled ( bool  enabled)
inline

Definition at line 206 of file LoadShedConfiguration.h.

References loadSheddingEnabled_.

206  {
207  loadSheddingEnabled_ = enabled;
208  }
void wangle::LoadShedConfiguration::setLoadUpdatePeriod ( std::chrono::milliseconds  period)
inline

Definition at line 183 of file LoadShedConfiguration.h.

References period_.

Referenced by TEST().

183  {
184  period_ = period;
185  }
std::chrono::milliseconds period_
void wangle::LoadShedConfiguration::setLogicalCpuCoreQuorum ( uint64_t  quorum)
inline

Set/get the number of most utilized cpu cores to use when comparing against cpu limits; a value of 0 or a value that equals the total number of cores on the executing system implies that mean CPU should be used. This field exists to more meaningfully handle uneven load distributions that can occur if for example network card interrupt affinity is set such that only X of Y cores are utilized for network packet processing.

Definition at line 153 of file LoadShedConfiguration.h.

References logicalCpuCoreQuorum_.

153  {
154  logicalCpuCoreQuorum_ = quorum;
155  }
void wangle::LoadShedConfiguration::setMaxActiveConnections ( uint64_t  maxActiveConns)
inline

Set/get the maximum number of active downstream connections across all VIPs.

Definition at line 80 of file LoadShedConfiguration.h.

References maxActiveConnections_.

Referenced by TEST().

80  {
81  maxActiveConnections_ = maxActiveConns;
82  }
void wangle::LoadShedConfiguration::setMaxConnections ( uint64_t  maxConns)
inline

Set/get the maximum number of downstream connections across all VIPs.

Definition at line 73 of file LoadShedConfiguration.h.

References maxConnections_.

Referenced by TEST().

void wangle::LoadShedConfiguration::setMaxCpuUsage ( double  max)
inline

Set/get the maximum cpu usage. Regarded as a soft limit; variable amount of new conn shedding should occur when above this limit.

Definition at line 126 of file LoadShedConfiguration.h.

References max, and maxCpuUsage_.

Referenced by TEST().

126  {
127  CHECK(max >= 0);
128  CHECK(max <= 1);
129  maxCpuUsage_ = max;
130  }
LogLevel max
Definition: LogLevel.cpp:31
void wangle::LoadShedConfiguration::setMaxMemUsage ( double  max)
inline

Set/get the maximum memory usage. Regarded as a soft limit; variable amount of new conn shedding should occur when above this limit.

Definition at line 114 of file LoadShedConfiguration.h.

References max, and maxMemUsage_.

Referenced by TEST().

114  {
115  CHECK(max >= 0);
116  CHECK(max <= 1);
117  maxMemUsage_ = max;
118  }
LogLevel max
Definition: LogLevel.cpp:31
void wangle::LoadShedConfiguration::setMaxTcpMemUsage ( double  max)
inline

Definition at line 188 of file LoadShedConfiguration.h.

References max, and maxTcpMemUsage_.

188  {
189  CHECK_GE(max, 0.0);
190  CHECK_LE(max, 1.0);
192  }
LogLevel max
Definition: LogLevel.cpp:31
void wangle::LoadShedConfiguration::setMinCpuIdle ( double  min)
inline

Set/get the minimum cpu idle. Regarded as a hard limit; every new conn should shed when above this limit when normalized.

Definition at line 138 of file LoadShedConfiguration.h.

References min, and minCpuIdle_.

Referenced by TEST().

138  {
139  CHECK(min >= 0);
140  CHECK(min <= 1);
141  minCpuIdle_ = min;
142  }
LogLevel min
Definition: LogLevel.cpp:30
void wangle::LoadShedConfiguration::setMinFreeMem ( uint64_t  min)
inline

Set/get the minium actual free memory on the system. Regarded as a hard limit; every new conn should shed when above this limit when normalized.

Definition at line 176 of file LoadShedConfiguration.h.

References min, and minFreeMem_.

Referenced by TEST().

176  {
177  minFreeMem_ = min;
178  }
LogLevel min
Definition: LogLevel.cpp:30
void wangle::LoadShedConfiguration::setMinFreeTcpMemPct ( double  min)
inline

Definition at line 197 of file LoadShedConfiguration.h.

References min, and minFreeTcpMemPct_.

197  {
198  CHECK_GE(min, 0.0);
199  CHECK_LE(min, 1.0);
201  }
LogLevel min
Definition: LogLevel.cpp:30
void wangle::LoadShedConfiguration::setWhitelistAddrs ( const AddressSet addrs)
inline

Set/get the set of IPs that should be whitelisted through even when we're trying to shed load.

Definition at line 58 of file LoadShedConfiguration.h.

References whitelistAddrs_.

Referenced by TEST().

void wangle::LoadShedConfiguration::setWhitelistNetworks ( const NetworkSet networks)
inline

Set/get the set of networks that should be whitelisted through even when we're trying to shed load.

Definition at line 65 of file LoadShedConfiguration.h.

References whitelistNetworks_.

Referenced by TEST().

65  {
66  whitelistNetworks_ = networks;
67  }

Member Data Documentation

uint64_t wangle::LoadShedConfiguration::acceptPauseOnAcceptorQueueSize_ {0}
private
uint64_t wangle::LoadShedConfiguration::acceptResumeOnAcceptorQueueSize_ {0}
private
uint64_t wangle::LoadShedConfiguration::cpuUsageExceedWindowSize_ {0}
private
bool wangle::LoadShedConfiguration::loadSheddingEnabled_ {true}
private
uint64_t wangle::LoadShedConfiguration::logicalCpuCoreQuorum_ {0}
private
uint64_t wangle::LoadShedConfiguration::maxActiveConnections_ {0}
private
uint64_t wangle::LoadShedConfiguration::maxConnections_ {0}
private

Definition at line 234 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMaxConnections(), and setMaxConnections().

double wangle::LoadShedConfiguration::maxCpuUsage_ {1.0}
private

Definition at line 240 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMaxCpuUsage(), and setMaxCpuUsage().

double wangle::LoadShedConfiguration::maxMemUsage_ {1.0}
private

Definition at line 239 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMaxMemUsage(), and setMaxMemUsage().

double wangle::LoadShedConfiguration::maxTcpMemUsage_ {1.0}
private

Definition at line 244 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMaxTcpMemUsage(), and setMaxTcpMemUsage().

double wangle::LoadShedConfiguration::minCpuIdle_ {0.0}
private

Definition at line 241 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMinCpuIdle(), and setMinCpuIdle().

uint64_t wangle::LoadShedConfiguration::minFreeMem_ {0}
private

Definition at line 238 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMinFreeMem(), and setMinFreeMem().

double wangle::LoadShedConfiguration::minFreeTcpMemPct_ {0.0}
private

Definition at line 245 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getMinFreeTcpMemPct(), and setMinFreeTcpMemPct().

std::chrono::milliseconds wangle::LoadShedConfiguration::period_
private

Definition at line 246 of file LoadShedConfiguration.h.

Referenced by checkIsSane(), getLoadUpdatePeriod(), and setLoadUpdatePeriod().

AddressSet wangle::LoadShedConfiguration::whitelistAddrs_
private
NetworkSet wangle::LoadShedConfiguration::whitelistNetworks_
private

The documentation for this class was generated from the following files: