]> granicus.if.org Git - pdns/commitdiff
make dnsdist like faster servers even more in leastOutstanding policy (which also...
authorbert hubert <bert.hubert@powerdns.com>
Tue, 17 Nov 2015 15:01:53 +0000 (16:01 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 17 Nov 2015 15:01:53 +0000 (16:01 +0100)
pdns/dnsdist.cc

index 38d266936c94c9d4a268ac1bc717ad03a9607b3c..b1b5d5cbc484aaef232e5931db56c1371c756590 100644 (file)
@@ -239,13 +239,16 @@ shared_ptr<DownstreamState> firstAvailable(const NumberedServerVector& servers,
   return leastOutstanding(servers, remote, qname, qtype, dh);
 }
 
+// get server with least outstanding queries, and within those, with the lowest order, and within those: the fastest
 shared_ptr<DownstreamState> leastOutstanding(const NumberedServerVector& servers, const ComboAddress& remote, const DNSName& qname, uint16_t qtype, dnsheader* dh)
 {
-  vector<pair<pair<int,int>, shared_ptr<DownstreamState>>> poss;
+  vector<pair<tuple<int,int,double>, shared_ptr<DownstreamState>>> poss;
+  /* so you might wonder, why do we go through this trouble? The data on which we sort could change during the sort,
+     which would suck royally and could even lead to crashes. So first we snapshot on what we sort, and then we sort */
   poss.reserve(servers.size());
   for(auto& d : servers) {    
     if(d.second->isUp()) {
-      poss.push_back({make_pair(d.second->outstanding.load(), d.second->order), d.second});
+      poss.push_back({make_tuple(d.second->outstanding.load(), d.second->order, d.second->latencyUsec), d.second});
     }
   }
   if(poss.empty())