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