From: Otto Moerbeek Date: Fri, 12 Jun 2020 10:24:26 +0000 (+0200) Subject: Fix three shared cache issues: X-Git-Tag: dnsdist-1.5.0-rc3~6^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9226%2Fhead;p=thirdparty%2Fpdns.git Fix three shared cache issues: - Only prime share cache once on startup - Cache pruning could go into an infinite loop if not enough expired entries could be pruned. - Handler thread isn't run very often, but now the record cache pruning is done by it, so increase frequency of the housekeeping call for the handler thread. --- diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index 18e5ea1474..7d42274bff 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -190,7 +190,7 @@ template uint64_t pruneMutexCollectionsVect toTrim -= totErased; - while (toTrim > 0) { + while (true) { size_t pershard = toTrim / maps_size + 1; for (auto& mc : maps) { const typename C::lock l(mc); @@ -204,11 +204,12 @@ template uint64_t pruneMutexCollectionsVect totErased++; toTrim--; if (toTrim == 0) { - break; + return totErased; } } } } + // Not reached return totErased; } diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8e51e26350..f99dd5af58 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4662,11 +4662,13 @@ try t_allowFrom = g_initialAllowFrom; t_udpclientsocks = std::unique_ptr(new UDPClientSocks()); t_tcpClientCounts = std::unique_ptr(new tcpClientCounts_t()); - primeHints(); + if (threadInfo.isHandler) { + primeHints(); + g_log<(new RecursorPacketCache()); - g_log<schedule(&g_now)); // MTasker letting the mthreads do their thing - if(!(counter%500)) { + // Use primes, it avoid not being scheduled in cases where the counter has a regular pattern. + // We want to call handler thread often, it gets scheduled about 2 times per second + if ((threadInfo.isHandler && counter % 11 == 0) || counter % 499 == 0) { MT->makeThread(houseKeeping, 0); }