From: Bert Hubert Date: Sun, 26 Mar 2006 10:51:55 +0000 (+0000) Subject: move negcache to boost::multi_index, make sure it gets pruned a bit faster. Also... X-Git-Tag: rec-3-0~125 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33988bfb7aa819f61267d4df99e84d95c03f9400;p=pdns move negcache to boost::multi_index, make sure it gets pruned a bit faster. Also, and this is controversial, cap SOA negative caching to 3600 seconds. This is done for two reasons: 1) the cache grows HUGE otherwise 2) I'm pretty sure anything >3600 seconds will annoy people a lot. git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@628 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index 5551e4652..3a1718841 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -1,11 +1,10 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 - 2005 PowerDNS.COM BV + Copyright (C) 2002 - 2006 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d64c94236..49794b389 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -48,7 +48,7 @@ #include "zoneparser-tng.hh" #include "rec_channel.hh" -// using namespace boost; +using namespace boost; #ifdef __FreeBSD__ // see cvstrac ticket #26 #include @@ -545,13 +545,12 @@ static void houseKeeping(void *) dt.setTimeval(now); RC.doPrune(); int pruned=0; - for(SyncRes::negcache_t::iterator i = SyncRes::s_negcache.begin(); i != SyncRes::s_negcache.end();) - if(i->second.ttd < now.tv_sec) { - SyncRes::s_negcache.erase(i++); - pruned++; - } - else - ++i; + + typedef SyncRes::negcache_t::nth_index<1>::type negcache_by_ttd_index_t; + negcache_by_ttd_index_t& ttdindex=boost::multi_index::get<1>(SyncRes::s_negcache); + + negcache_by_ttd_index_t::iterator i=ttdindex.lower_bound(now.tv_sec); + ttdindex.erase(ttdindex.begin(), i); time_t limit=now.tv_sec-300; for(SyncRes::nsspeeds_t::iterator i = SyncRes::s_nsSpeeds.begin() ; i!= SyncRes::s_nsSpeeds.end(); ) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index cfe9d99cc..8f9a3d538 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -111,7 +111,7 @@ RecursorControlParser::RecursorControlParser() addGetStat("cache-hits", &RC.cacheHits); addGetStat("cache-misses", &RC.cacheMisses); - addGetStat("cache-entries", bind(&MemRecursorCache::size, ref(RC))); + addGetStat("cache-entries", boost::bind(&MemRecursorCache::size, ref(RC))); addGetStat("servfail-answers", &g_stats.servFails); addGetStat("nxdomain-answers", &g_stats.nxDomains); addGetStat("noerror-answers", &g_stats.noErrors); @@ -125,11 +125,11 @@ RecursorControlParser::RecursorControlParser() addGetStat("qa-latency", &g_stats.avgLatencyUsec); addGetStat("all-questions", &qcounter); - addGetStat("negcache-entries", bind(&SyncRes::negcache_t::size, ref(SyncRes::s_negcache))); - addGetStat("throttle-entries", bind(&SyncRes::throttle_t::size, ref(SyncRes::s_throttle))); - addGetStat("nsspeeds-entries", bind(&SyncRes::nsspeeds_t::size, ref(SyncRes::s_nsSpeeds))); + addGetStat("negcache-entries", boost::bind(&SyncRes::negcache_t::size, ref(SyncRes::s_negcache))); + addGetStat("throttle-entries", boost::bind(&SyncRes::throttle_t::size, ref(SyncRes::s_throttle))); + addGetStat("nsspeeds-entries", boost::bind(&SyncRes::nsspeeds_t::size, ref(SyncRes::s_nsSpeeds))); - addGetStat("concurrent-queries", bind(&MTasker::numProcesses, ref(MT))); + addGetStat("concurrent-queries", boost::bind(&MTasker::numProcesses, ref(MT))); addGetStat("outgoing-timeouts", &SyncRes::s_outgoingtimeouts); addGetStat("tcp-outqueries", &SyncRes::s_tcpoutqueries); addGetStat("all-outqueries", &SyncRes::s_outqueries); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 5ec4007b1..5940cc736 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -248,20 +248,21 @@ bool SyncRes::doCacheCheck(const string &qname, const QType &qtype, vectorsecond.ttd) { - sttl=ni->second.ttd - d_now.tv_sec; + if((uint32_t)d_now.tv_sec < ni->d_ttd) { + sttl=ni->d_ttd - d_now.tv_sec; LOG<second.name; + sqname=ni->d_qname; sqt="SOA"; } else { LOG<second.ttd) { - sttl=ni->second.ttd - d_now.tv_sec; + if((uint32_t)d_now.tv_sec < ni->d_ttd) { + sttl=ni->d_ttd - d_now.tv_sec; LOG<second.name; + sqname=ni->d_qname; sqt="SOA"; } else { LOG< nameservers, string auth, const string &qna ret.push_back(*i); NegCacheEntry ne; - ne.name=i->qname; - ne.ttd=d_now.tv_sec + i->ttl; - s_negcache[toLower(qname)]=ne; + + ne.d_qname=i->qname; + ne.d_ttd=d_now.tv_sec + min(i->ttl, 3600U); // controversial + ne.d_name=toLower(qname); + s_negcache.insert(ne); negindic=true; } else if(i->d_place==DNSResourceRecord::ANSWER && i->qname==qname && i->qtype.getCode()==QType::CNAME && (!(qtype==QType(QType::CNAME)))) { @@ -567,9 +570,10 @@ int SyncRes::doResolveAt(set nameservers, string auth, const string &qna ret.push_back(*i); NegCacheEntry ne; - ne.name=i->qname; - ne.ttd=d_now.tv_sec + i->ttl; - s_negcache[toLower(qname)+"|"+qtype.getName()]=ne; + ne.d_qname=i->qname; + ne.d_ttd=d_now.tv_sec + min(3600U,i->ttl); + ne.d_name=toLower(qname)+"|"+qtype.getName(); + s_negcache.insert(ne); negindic=true; } } diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 788978f4f..f11eafcaa 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -25,8 +25,9 @@ void primeHints(void); struct NegCacheEntry { - string name; - time_t ttd; + string d_qname; + string d_name; + uint32_t d_ttd; }; @@ -240,7 +241,19 @@ public: unsigned int d_tcpoutqueries; unsigned int d_throttledqueries; unsigned int d_timeouts; - typedef map negcache_t; + // typedef map negcache_t; + + typedef multi_index_container < + NegCacheEntry, + indexed_by < + ordered_unique< + member + >, + ordered_non_unique< + member + > + > + >negcache_t; static negcache_t s_negcache; typedef map nsspeeds_t;