From: Bert Hubert Date: Sat, 11 Sep 2010 13:40:03 +0000 (+0000) Subject: enable cache cleaner to clean some caches more agressively, plus make pdns use this... X-Git-Tag: rec-3.3~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a16adf0a289d88adc1b807a763d39824d4d6d7c;p=pdns enable cache cleaner to clean some caches more agressively, plus make pdns use this to clean the negcache more agressively, plus to keep it smaller by default. Spotted by Imre Gergely git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1712 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index defd3a4a7..60ae08f27 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -4,7 +4,7 @@ // this function can clean any cache that has a getTTD() method on its entries, and a 'sequence' index as its second index // the ritual is that the oldest entries are in *front* of the sequence collection, so on a hit, move an item to the end // on a miss, move it to the beginning -template void pruneCollection(T& collection, unsigned int maxCached) +template void pruneCollection(T& collection, unsigned int maxCached, unsigned int scanFraction=1000) { uint32_t now=(uint32_t)time(0); unsigned int toTrim=0; @@ -22,12 +22,13 @@ template void pruneCollection(T& collection, unsigned int maxCached unsigned int tried=0, lookAt, erased=0; - // two modes - if toTrim is 0, just look through 10000 records and nuke everything that is expired + // two modes - if toTrim is 0, just look through 1/scanFraction of all records + // and nuke everything that is expired // otherwise, scan first 5*toTrim records, and stop once we've nuked enough if(toTrim) lookAt=5*toTrim; else - lookAt=cacheSize/1000; + lookAt=cacheSize/scanFraction; typename sequence_t::iterator iter=sidx.begin(), eiter; for(; iter != sidx.end() && tried < lookAt ; ++tried) { diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2b2b36ed4..537ee7bca 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1084,7 +1084,7 @@ try struct timeval now; Utility::gettimeofday(&now, 0); -// clog<<"* "< (time_t)(5 + t_id)) { DTime dt; @@ -1092,7 +1092,7 @@ try t_RC->doPrune(); // this function is local to a thread, so fine anyhow t_packetCache->doPruneTo(::arg().asNum("max-packetcache-entries") / g_numThreads); - pruneCollection(t_sstorage->negcache, ::arg().asNum("max-cache-entries") / (g_numThreads * 5)); + pruneCollection(t_sstorage->negcache, ::arg().asNum("max-cache-entries") / (g_numThreads * 10), 200); if(!((cleanCounter++)%40)) { // this is a full scan! time_t limit=now.tv_sec-300;