]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Account for the health-check run time between two runs 12821/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 11 May 2023 13:07:01 +0000 (15:07 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 May 2023 12:54:54 +0000 (14:54 +0200)
We used to wait one full second between every run, which only makes
sense if the runs are not taking a long time. But as soon as we have
at least one check timing out, the run is taking roughly the time
of the longest timeout configured, so after this commit we:
- do not wait at all if the last run took more than a full second
- wait one second minus the elapsed time of the last run otherwise

(cherry picked from commit 5b48dd1425dabbba7ab6758fe3ccf2b1410faef7)

pdns/dnsdist.cc

index 36d279e043e1dba523012e4b17767bc4cb480eba..7642b3a2d139d530a2cc64c34f28e87961e18b4c 100644 (file)
@@ -2027,11 +2027,24 @@ static void healthChecksThread()
 {
   setThreadName("dnsdist/healthC");
 
-  constexpr int interval = 1;
+  constexpr int intervalUsec = 1000 * 1000;
+  struct timeval lastRound{
+    .tv_sec = 0,
+    .tv_usec = 0
+  };
   auto states = g_dstates.getLocal(); // this points to the actual shared_ptrs!
 
   for (;;) {
-    sleep(interval);
+    struct timeval now;
+    gettimeofday(&now, nullptr);
+    auto elapsedTimeUsec = uSec(now - lastRound);
+    if (elapsedTimeUsec < intervalUsec) {
+      usleep(intervalUsec - elapsedTimeUsec);
+      gettimeofday(&lastRound, nullptr);
+    }
+    else {
+      lastRound = now;
+    }
 
     std::unique_ptr<FDMultiplexer> mplexer{nullptr};
     for (auto& dss : *states) {