2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
13 #include <folly/Range.h>
14 #include <folly/SocketAddress.h>
15 #include <glog/logging.h>
20 #include <folly/wangle/acceptor/NetworkAddress.h>
25 * Class that holds an LoadShed configuration for a service
27 class LoadShedConfiguration {
30 // Comparison function for SocketAddress that disregards the port
31 struct AddressOnlyCompare {
33 const SocketAddress& addr1,
34 const SocketAddress& addr2) const {
35 return addr1.getIPAddress() < addr2.getIPAddress();
39 typedef std::set<SocketAddress, AddressOnlyCompare> AddressSet;
40 typedef std::set<NetworkAddress> NetworkSet;
42 LoadShedConfiguration() = default;
44 ~LoadShedConfiguration() = default;
46 void addWhitelistAddr(folly::StringPiece);
49 * Set/get the set of IPs that should be whitelisted through even when we're
50 * trying to shed load.
52 void setWhitelistAddrs(const AddressSet& addrs) { whitelistAddrs_ = addrs; }
53 const AddressSet& getWhitelistAddrs() const { return whitelistAddrs_; }
56 * Set/get the set of networks that should be whitelisted through even
57 * when we're trying to shed load.
59 void setWhitelistNetworks(const NetworkSet& networks) {
60 whitelistNetworks_ = networks;
62 const NetworkSet& getWhitelistNetworks() const { return whitelistNetworks_; }
65 * Set/get the maximum number of downstream connections across all VIPs.
67 void setMaxConnections(uint64_t maxConns) { maxConnections_ = maxConns; }
68 uint64_t getMaxConnections() const { return maxConnections_; }
71 * Set/get the maximum cpu usage.
73 void setMaxMemUsage(double max) {
78 double getMaxMemUsage() const { return maxMemUsage_; }
81 * Set/get the maximum memory usage.
83 void setMaxCpuUsage(double max) {
88 double getMaxCpuUsage() const { return maxCpuUsage_; }
91 * Set/get the minium actual free memory on the system.
93 void setMinFreeMem(uint64_t min) {
96 uint64_t getMinFreeMem() const {
100 void setLoadUpdatePeriod(std::chrono::milliseconds period) {
103 std::chrono::milliseconds getLoadUpdatePeriod() const { return period_; }
105 bool isWhitelisted(const SocketAddress& addr) const;
109 AddressSet whitelistAddrs_;
110 NetworkSet whitelistNetworks_;
111 uint64_t maxConnections_{0};
112 uint64_t minFreeMem_{0};
115 std::chrono::milliseconds period_;