From 017337515725264173e4d1f254bc0a19e4da6f4a Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 21 Mar 2022 10:27:30 +0100 Subject: [PATCH] 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. --- pdns/dnsdist.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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); + } } } -- 2.47.2