Go to the documentation of this file.
25 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
42 return (*p1)->
weight - (*p2)->weight;
55 double P_last, X_last, Xn;
68 const auto p = peer.get();
78 rawCarpPeers.push_back(p);
83 if (rawCarpPeers.empty())
87 for (
const auto p: rawCarpPeers) {
91 for (t = p->name; *t != 0; ++t)
94 p->carp.hash += p->carp.hash * 0x62531965;
101 if (floor(p->carp.load_factor * 1000.0) == 0.0)
102 p->carp.load_factor = 0.0;
106 qsort(rawCarpPeers.data(), rawCarpPeers.size(),
sizeof(decltype(rawCarpPeers)::value_type),
peerSortWeight);
116 const auto K = rawCarpPeers.size();
124 for (
size_t k = 1; k <= K; ++k) {
125 double Kk1 = (
double) (K - k + 1);
126 const auto p = rawCarpPeers[k - 1];
127 p->carp.load_multiplier = (Kk1 * (p->carp.load_factor - P_last)) / Xn;
128 p->carp.load_multiplier += pow(X_last, Kk1);
129 p->carp.load_multiplier = pow(p->carp.load_multiplier, 1.0 / Kk1);
130 Xn *= p->carp.load_multiplier;
131 X_last = p->carp.load_multiplier;
132 P_last = p->carp.load_factor;
135 CarpPeers().assign(rawCarpPeers.begin(), rawCarpPeers.end());
156 unsigned int user_hash = 0;
157 unsigned int combined_hash;
159 double high_score = 0;
173 if (tp->options.carp_key.set) {
176 if (tp->options.carp_key.scheme) {
181 if (tp->options.carp_key.host) {
184 if (tp->options.carp_key.port) {
187 if (tp->options.carp_key.path) {
191 if (tp->options.carp_key.params) {
207 combined_hash = (user_hash ^ tp->carp.hash);
208 combined_hash += combined_hash * 0x62531965;
210 score = combined_hash * tp->carp.load_multiplier;
211 debugs(39, 3, *tp <<
" key=" << key <<
" combined_hash=" << combined_hash <<
212 " score=" << std::setprecision(0) << score);
214 if ((score > high_score) &&
peerHTTPOkay(tp.get(), ps)) {
221 debugs(39, 2,
"selected " << *p);
240 sumfetches += p->stats.fetches;
247 p->name, p->carp.hash,
248 p->carp.load_multiplier,
250 sumfetches ? (
double) p->stats.fetches / sumfetches : -1.0);
static auto & CarpPeers()
CARP cache_peers ordered by their CARP weight.
reacts to RegisteredRunner events relevant to this module
AnyP::Uri url
the request URI
void useConfig() override
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
void syncConfig() override
static int peerSortWeight(const void *a, const void *b)
const char * rawContent() const
DefineRunnerRegistrator(CarpRr)
MemBlob::size_type size_type
#define ROTATE_LEFT(x, n)
static void carpRegisterWithCacheManager(void)
std::vector< CbcPointer< CachePeer >, PoolingAllocator< CbcPointer< CachePeer > > > SelectedCachePeers
std::vector< CachePeer *, PoolingAllocator< CachePeer * > > RawCachePeers
Temporary, local storage of raw pointers to zero or more Config.peers.
static void carpInit(void)
const AnyP::UriScheme & getScheme() const
void port(const Port p)
reset authority port subcomponent
size_type length() const
Returns the number of bytes stored in SBuf.
SBuf & append(const SBuf &S)
static const size_type npos
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
const CachePeers & CurrentCachePeers()
int peerHTTPOkay(const CachePeer *p, PeerSelector *ps)
SBuf & appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
CachePeer * carpSelectParent(PeerSelector *ps)
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
void host(const char *src)
#define debugs(SECTION, LEVEL, CONTENT)