]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist-1.7.x: Only allocate the health-check mplexer when needed 11580/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 Mar 2022 09:27:30 +0000 (10:27 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 26 Apr 2022 08:07:16 +0000 (10:07 +0200)
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

index ea09c45487b99d3b31c3fa8bad136529cd6d3094..057375cf5595a7a079740a0b62ba2db673aa89d1 100644 (file)
@@ -1847,7 +1847,8 @@ static void healthChecksThread()
   for(;;) {
     sleep(interval);
 
-    auto mplexer = std::unique_ptr<FDMultiplexer>(FDMultiplexer::getMultiplexerSilent());
+    std::unique_ptr<FDMultiplexer> 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>(FDMultiplexer::getMultiplexerSilent());
+        }
+
         if (!queueHealthCheck(mplexer, dss)) {
           updateHealthCheckResult(dss, false, false);
         }
       }
-
     }
 
-    handleQueuedHealthChecks(*mplexer);
+    if (mplexer) {
+      handleQueuedHealthChecks(*mplexer);
+    }
   }
 }