From: Otto Moerbeek Date: Wed, 4 Dec 2019 14:35:40 +0000 (+0100) Subject: wip2 X-Git-Tag: dnsdist-1.5.0-alpha1~21^2^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdde245827033e9635d6de0003e25362e7e5e304;p=thirdparty%2Fpdns.git wip2 --- diff --git a/pdns/auth-packetcache.hh b/pdns/auth-packetcache.hh index bc3c2f35bd..0d3af47a25 100644 --- a/pdns/auth-packetcache.hh +++ b/pdns/auth-packetcache.hh @@ -89,11 +89,6 @@ private: uint32_t hash{0}; uint16_t qtype{0}; bool tcp{false}; - - time_t getTTD() const - { - return ttd; - } }; struct HashTag{}; @@ -150,9 +145,4 @@ private: bool d_cleanskipped{false}; static const unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000; - -public: - void preRemoval(const CacheEntry&) - { - } }; diff --git a/pdns/auth-querycache.hh b/pdns/auth-querycache.hh index 00465ad73e..889634bb60 100644 --- a/pdns/auth-querycache.hh +++ b/pdns/auth-querycache.hh @@ -68,11 +68,6 @@ private: mutable time_t ttd{0}; uint16_t qtype{0}; int zoneID{-1}; - - time_t getTTD() const - { - return ttd; - } }; struct HashTag{}; @@ -131,9 +126,4 @@ private: bool d_cleanskipped{false}; static const unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000; - -public: - void preRemoval(const CacheEntry&) - { - } }; diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index 9d57ede009..a4dfe8863d 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -133,7 +133,7 @@ template uint64_t pruneLockedCollectionsVector(vector(mc.d_map); uint64_t erased = 0, lookedAt = 0; for(auto i = sidx.begin(); i != sidx.end(); lookedAt++) { - if (i->getTTD() < now) { + if (i->ttd < now) { i = sidx.erase(i); erased++; } else { @@ -177,6 +177,7 @@ template uint64_t pruneMutexCollectionsVect container.preRemoval(*i); i = sidx.erase(i); erased++; + mc.d_entriesCount--; } else { ++i; } @@ -206,6 +207,7 @@ template uint64_t pruneMutexCollectionsVect auto i = sidx.begin(); container.preRemoval(*i); i = sidx.erase(i); + mc.d_entriesCount--; totErased++; toTrim--; if (toTrim == 0) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d8a09f3af6..b54a91fbe4 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2844,12 +2844,13 @@ static void doStats(void) static time_t lastOutputTime; static uint64_t lastQueryCount; - uint64_t cacheHits = broadcastAccFunction(pleaseGetCacheHits); - uint64_t cacheMisses = broadcastAccFunction(pleaseGetCacheMisses); + uint64_t cacheHits = s_RC->cacheHits; + uint64_t cacheMisses = s_RC->cacheMisses; + uint64_t cacheSize = s_RC->size(); if(g_stats.qcounter && (cacheHits + cacheMisses) && SyncRes::s_queries && SyncRes::s_outqueries) { g_log<(pleaseGetCacheSize)<< " cache entries, "<< + cacheSize << " cache entries, "<< broadcastAccFunction(pleaseGetNegCacheSize)<<" negative entries, "<< (int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"<doPruneTo(g_maxPacketCacheEntries / g_numWorkerThreads); - SyncRes::pruneNegCache(g_maxCacheEntries / (g_numWorkerThreads * 10)); time_t limit; @@ -2932,15 +2933,19 @@ static void houseKeeping(void *) Utility::gettimeofday(&last_prune, nullptr); } - if(now.tv_sec - last_rootupdate > 7200) { - int res = SyncRes::getRootNS(g_now, nullptr); - if (!res) { - last_rootupdate=now.tv_sec; - primeRootNSZones(g_dnssecmode != DNSSECMode::Off); - } - } - if(isHandlerThread()) { + if (now.tv_sec - last_RC_prune > 5) { + s_RC->doPrune(g_maxCacheEntries); + last_RC_prune = now.tv_sec; + } + // XXX !!! global + if(now.tv_sec - last_rootupdate > 7200) { + int res = SyncRes::getRootNS(g_now, nullptr); + if (!res) { + last_rootupdate=now.tv_sec; + primeRootNSZones(g_dnssecmode != DNSSECMode::Off); + } + } if(now.tv_sec - last_secpoll >= 3600) { try { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index b09f3b6d7c..8829be099d 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -213,7 +213,7 @@ static uint64_t dumpNegCache(NegCache& negcache, int fd) static uint64_t* pleaseDump(int fd) { - return new uint64_t(s_RC->doDump(fd) + dumpNegCache(SyncRes::t_sstorage.negcache, fd) + t_packetCache->doDump(fd)); + return new uint64_t(dumpNegCache(SyncRes::t_sstorage.negcache, fd) + t_packetCache->doDump(fd)); } static uint64_t* pleaseDumpEDNSMap(int fd) @@ -281,7 +281,7 @@ static string doDumpCache(T begin, T end) return "Error opening dump file for writing: "+stringerror()+"\n"; uint64_t total = 0; try { - total = broadcastAccFunction(boost::bind(pleaseDump, fd)); + total = s_RC->doDump(fd) + broadcastAccFunction(boost::bind(pleaseDump, fd)); } catch(...){} @@ -932,19 +932,9 @@ static uint64_t getConcurrentQueries() return broadcastAccFunction(pleaseGetConcurrentQueries); } -uint64_t* pleaseGetCacheSize() -{ - return new uint64_t(s_RC ? s_RC->size() : 0); -} - -static uint64_t* pleaseGetCacheBytes() -{ - return new uint64_t(s_RC ? s_RC->bytes() : 0); -} - static uint64_t doGetCacheSize() { - return broadcastAccFunction(pleaseGetCacheSize); + return s_RC->size(); } static uint64_t doGetAvgLatencyUsec() @@ -954,27 +944,17 @@ static uint64_t doGetAvgLatencyUsec() static uint64_t doGetCacheBytes() { - return broadcastAccFunction(pleaseGetCacheBytes); -} - -uint64_t* pleaseGetCacheHits() -{ - return new uint64_t(s_RC->cacheHits); + return s_RC->bytes(); } static uint64_t doGetCacheHits() { - return broadcastAccFunction(pleaseGetCacheHits); -} - -uint64_t* pleaseGetCacheMisses() -{ - return new uint64_t(s_RC->cacheMisses); + return s_RC->cacheHits; } static uint64_t doGetCacheMisses() { - return broadcastAccFunction(pleaseGetCacheMisses); + return s_RC->cacheMisses; } uint64_t* pleaseGetPacketCacheSize() diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index cfe65173e9..3464b7f756 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -36,8 +36,7 @@ size_t MemRecursorCache::size() // XXX! size_t count = 0; for (auto& map : d_maps) { - const std::lock_guard lock(map.mutex); - count += map.d_map.size(); + count += map.d_entriesCount; } return count; } @@ -286,6 +285,7 @@ void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType& qt cache_t::iterator stored = map.d_map.find(key); if (stored == map.d_map.end()) { stored = map.d_map.insert(CacheEntry(key, auth)).first; + map.d_entriesCount++; isNew = true; } @@ -362,21 +362,22 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, uint16_t qty size_t count = 0; if (!sub) { - for (auto& map : d_maps) { - const std::lock_guard lock(map.mutex); - map.d_cachecachevalid = false; - auto& idx = map.d_map.get(); - count += idx.erase(name); - if (qtype == 0xffff) { - auto& ecsIdx = map.d_ecsIndex.get(); - auto ecsIndexRange = ecsIdx.equal_range(name); - ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second); - } - else { - auto& ecsIdx = map.d_ecsIndex.get(); - auto ecsIndexRange = ecsIdx.equal_range(tie(name, qtype)); - ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second); - } + auto& map = getMap(name); + const std::lock_guard lock(map.mutex); + map.d_cachecachevalid = false; + auto& idx = map.d_map.get(); + size_t n = idx.erase(name); + count += n; + map.d_entriesCount -= n; + if (qtype == 0xffff) { + auto& ecsIdx = map.d_ecsIndex.get(); + auto ecsIndexRange = ecsIdx.equal_range(name); + ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second); + } + else { + auto& ecsIdx = map.d_ecsIndex.get(); + auto ecsIndexRange = ecsIdx.equal_range(tie(name, qtype)); + ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second); } } else { @@ -390,6 +391,7 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, uint16_t qty if (i->d_qtype == qtype || qtype == 0xffff) { count++; i = idx.erase(i); + map.d_entriesCount--; } else { ++i; } diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index 48bcbb2954..db5bd4766e 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -202,8 +202,9 @@ private: ecsIndex_t d_ecsIndex; DNSName d_cachedqname; std::pair d_cachecache; - bool d_cachecachevalid{false}; std::mutex mutex; + bool d_cachecachevalid{false}; + std::atomic d_entriesCount{0}; }; vector d_maps; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index ae9187a906..b8021447d7 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -1091,10 +1091,7 @@ std::shared_ptr parseAuthAndForwards(); uint64_t* pleaseGetNsSpeedsSize(); uint64_t* pleaseGetFailedServersSize(); uint64_t* pleaseGetEDNSStatusesSize(); -uint64_t* pleaseGetCacheSize(); uint64_t* pleaseGetNegCacheSize(); -uint64_t* pleaseGetCacheHits(); -uint64_t* pleaseGetCacheMisses(); uint64_t* pleaseGetConcurrentQueries(); uint64_t* pleaseGetThrottleSize(); uint64_t* pleaseGetPacketCacheHits();