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

index b3b01859591367d58c8942bab21a62d263b14ae8..e1036faa0358a2aae4755d66ac2e3144b6931340 100644 (file)
@@ -1830,7 +1830,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) {
       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>(FDMultiplexer::getMultiplexerSilent());
+        }
+
         if (!queueHealthCheck(mplexer, dss)) {
           updateHealthCheckResult(dss, false, false);
         }
       }
     }
 
-    handleQueuedHealthChecks(*mplexer);
+    if (mplexer) {
+      handleQueuedHealthChecks(*mplexer);
+    }
   }
 }