From: Remi Gacogne Date: Mon, 21 Mar 2022 09:27:30 +0000 (+0100) Subject: dnsdist: Only allocate the health-check mplexer when needed X-Git-Tag: rec-4.7.0-beta1~30^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F11437%2Fhead;p=thirdparty%2Fpdns.git dnsdist: 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. --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index b3b0185959..e1036faa03 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1830,7 +1830,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) { auto delta = dss->sw.udiffAndSet()/1000000.0; @@ -1849,13 +1850,19 @@ static void healthChecksThread() dss->d_nextCheck = dss->d_config.checkInterval; if (dss->d_config.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); + } } }