exceeded its QPS limit gets the traffic.
A further policy, 'wrandom' assigns queries randomly, but based on the
-'weight' parameter passed to `newServer`
+'weight' parameter passed to `newServer`. `whashed` is a similar weighted policy,
+but assigns questions with identical hash to identical servers, allowing for
+better cache concentration ('sticky queries').
If you don't like the default policies you can create your own, like this
for example:
* `newServerPolicy(name, function)`: create a policy object from a Lua function
* Available policies:
* `firstAvailable`: Pick first server that has not exceeded its QPS limit, ordered by the server 'order' parameter
+ * `whashed`: Weighted hashed ('sticky') distribution over available servers, based on the server 'weight' parameter
* `wrandom`: Weighted random over available servers, based on the server 'weight' parameter
* `roundrobin`: Simple round robin over available servers
* `leastOutstanding`: Send traffic to downstream server with least outstanding queries, with the lowest 'order', and within that the lowest recent latency
g_lua.writeVariable("firstAvailable", ServerPolicy{"firstAvailable", firstAvailable});
g_lua.writeVariable("roundrobin", ServerPolicy{"roundrobin", roundrobin});
g_lua.writeVariable("wrandom", ServerPolicy{"wrandom", wrandom});
+ g_lua.writeVariable("whashed", ServerPolicy{"whashed", whashed});
g_lua.writeVariable("leastOutstanding", ServerPolicy{"leastOutstanding", leastOutstanding});
g_lua.writeFunction("addACL", [](const std::string& domain) {
g_ACL.modify([domain](NetmaskGroup& nmg) { nmg.addMask(domain); });
return poss.begin()->second;
}
-shared_ptr<DownstreamState> wrandom(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
+shared_ptr<DownstreamState> valrandom(unsigned int val, const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
{
vector<pair<int, shared_ptr<DownstreamState>>> poss;
int sum=0;
if(d.second->isUp()) {
sum+=d.second->weight;
poss.push_back({sum, d.second});
-
}
}
if(poss.empty())
return shared_ptr<DownstreamState>();
- int r = random() % sum;
+ int r = val % sum;
auto p = upper_bound(poss.begin(), poss.end(),r, [](int r, const decltype(poss)::value_type& a) { return r < a.first;});
if(p==poss.end())
return shared_ptr<DownstreamState>();
return p->second;
}
+shared_ptr<DownstreamState> wrandom(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
+{
+ return valrandom(random(), servers, remote, qname, qtype, dh);
+}
+
+shared_ptr<DownstreamState> whashed(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
+{
+ return valrandom(qname.hash(), servers, remote, qname, qtype, dh);
+}
+
+
shared_ptr<DownstreamState> roundrobin(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
{
NumberedServerVector poss;
std::shared_ptr<DownstreamState> leastOutstanding(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh);
std::shared_ptr<DownstreamState> wrandom(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh);
+std::shared_ptr<DownstreamState> whashed(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh);
std::shared_ptr<DownstreamState> roundrobin(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh);
int getEDNSZ(const char* packet, unsigned int len);
void dnsdistWebserverThread(int sock, const ComboAddress& local, const string& password);