From: Remi Gacogne Date: Mon, 21 Mar 2022 09:27:30 +0000 (+0100) Subject: dnsdist-1.7.x: Only allocate the health-check mplexer when needed X-Git-Tag: dnsdist-1.7.2~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11580%2Fhead;p=thirdparty%2Fpdns.git dnsdist-1.7.x: Only allocate the health-check mplexer when needed When health-checking is disabled, or when a check delay longer than one second is used, there is no need to allocate a new multiplexer object every second. (cherry picked from commit 017337515725264173e4d1f254bc0a19e4da6f4a) --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index ea09c45487..057375cf55 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1847,7 +1847,8 @@ static void healthChecksThread() for(;;) { sleep(interval); - auto mplexer = std::unique_ptr(FDMultiplexer::getMultiplexerSilent()); + std::unique_ptr mplexer{nullptr}; + auto states = g_dstates.getLocal(); // this points to the actual shared_ptrs! for(auto& dss : *states) { @@ -1900,14 +1901,19 @@ static void healthChecksThread() dss->lastCheck = 0; if (dss->availability == DownstreamState::Availability::Auto) { + if (!mplexer) { + mplexer = std::unique_ptr(FDMultiplexer::getMultiplexerSilent()); + } + if (!queueHealthCheck(mplexer, dss)) { updateHealthCheckResult(dss, false, false); } } - } - handleQueuedHealthChecks(*mplexer); + if (mplexer) { + handleQueuedHealthChecks(*mplexer); + } } }