From: phonedph1 Date: Wed, 10 Jan 2018 16:15:25 +0000 (+0000) Subject: Keep track of forward-zones NS speeds by stuffing them into the nsspeed collection. X-Git-Tag: dnsdist-1.3.0~129^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=589884b8f168b18b387916d3db97bbbcf6403c30;p=pdns Keep track of forward-zones NS speeds by stuffing them into the nsspeed collection. Use a similar method to shuffleInSpeedOrder for sorting and trace log printing. --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index f31621e02..2a1137f7e 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1282,6 +1282,45 @@ inline vector SyncRes::shuffleInSpeedOrder(NsSet &tnameservers, const s return rnameservers; } +inline vector SyncRes::shuffleForwardSpeed(vector &nameservers, const string &prefix, const bool wasRd) +{ + vector out_nameservers; + vector rnameservers; + for(const auto& ns:nameservers) { + rnameservers.push_back(DNSName(ns.toStringWithPort())); + } + + map speeds; + + for(const auto& val: rnameservers) { + double speed; + speed=t_sstorage.nsSpeeds[val].get(&d_now); + speeds[val]=speed; + } + random_shuffle(rnameservers.begin(),rnameservers.end(), dns_random); + speedOrder so(speeds); + stable_sort(rnameservers.begin(),rnameservers.end(), so); + + for(vector::const_iterator i=rnameservers.cbegin();i!=rnameservers.cend();++i) { + out_nameservers.push_back(ComboAddress(i->toStringNoDot())); + } + + if(doLog()) { + LOG(prefix<<"Nameservers: "); + for(vector::const_iterator i=rnameservers.cbegin();i!=rnameservers.cend();++i) { + if(i!=rnameservers.cbegin()) { + LOG(", "); + if(!((i-rnameservers.cbegin())%3)) { + LOG(endl<toStringNoDot() <<"(" << (boost::format("%0.2f") % (speeds[*i]/1000.0)).str() <<"ms)"); + } + LOG(endl); + } + return out_nameservers; +} + static uint32_t getRRSIGTTL(const time_t now, const std::shared_ptr& rrsig) { uint32_t res = 0; @@ -1419,13 +1458,13 @@ vector SyncRes::retrieveAddressesForNS(const std::string& prefix, else { LOG(prefix< 1) { + if(nameservers[*tns].first.size() > 1) { LOG("s"); } LOG(endl); sendRDQuery = nameservers[*tns].second; + result = shuffleForwardSpeed(nameservers[*tns].first, doLog() ? (prefix+qname.toString()+": ") : string(), sendRDQuery); pierceDontQuery=true; } return result; @@ -2422,7 +2461,7 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, } if(resolveret != -2) { // don't account for resource limits, they are our own fault - t_sstorage.nsSpeeds[nsName].submit(remoteIP, 1000000, &d_now); // 1 sec + t_sstorage.nsSpeeds[nsName.empty()? DNSName(remoteIP.toStringWithPort()) : nsName].submit(remoteIP, 1000000, &d_now); // 1 sec // code below makes sure we don't filter COM or the root if (s_serverdownmaxfails > 0 && (auth != g_rootdnsname) && t_sstorage.fails.incr(remoteIP) >= s_serverdownmaxfails) { @@ -2722,7 +2761,7 @@ int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, con */ // cout<<"msec: "<empty()? DNSName(remoteIP->toStringWithPort()) : *tns].submit(*remoteIP, lwr.d_usec, &d_now); /* we have received an answer, are we done ? */ bool done = processAnswer(depth, lwr, qname, qtype, auth, wasForwarded, ednsmask, sendRDQuery, nameservers, ret, luaconfsLocal->dfe, &gotNewServers, &rcode, state); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 33dae0480..89346906a 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -739,6 +739,7 @@ private: DNSName getBestNSNamesFromCache(const DNSName &qname, const QType &qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere); inline vector shuffleInSpeedOrder(NsSet &nameservers, const string &prefix); + inline vector shuffleForwardSpeed(vector &nameservers, const string &prefix, const bool wasRd); bool moreSpecificThan(const DNSName& a, const DNSName &b) const; vector getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly);