]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: fix rounding inaccuracy in latency statistics
authorKees Monshouwer <mind04@monshouwer.org>
Tue, 24 Nov 2020 19:50:34 +0000 (20:50 +0100)
committermind04 <mind04@monshouwer.org>
Thu, 26 Nov 2020 23:14:54 +0000 (00:14 +0100)
pdns/common_startup.cc
pdns/common_startup.hh

index 437ca3f7084f6c78cd891fcae5d54970a78e6a00..fa00fb1d9f53076f059054a0222b351d70f57363 100644 (file)
@@ -58,7 +58,7 @@ std::unique_ptr<DNSProxy> DP{nullptr};
 std::unique_ptr<DynListener> dl{nullptr};
 CommunicatorClass Communicator;
 shared_ptr<UDPNameserver> N;
-int avg_latency;
+double avg_latency{0.0};
 unique_ptr<TCPNameserver> TN;
 static vector<DNSDistributor*> g_distributors;
 vector<std::shared_ptr<UDPNameserver> > g_udpReceivers;
@@ -295,7 +295,7 @@ catch(PDNSException& e)
 
 static uint64_t getLatency(const std::string& str) 
 {
-  return avg_latency;
+  return round(avg_latency);
 }
 
 void declareStats(void)
@@ -399,7 +399,7 @@ static void sendout(std::unique_ptr<DNSPacket>& a)
   N->send(*a);
 
   int diff=a->d_dt.udiff();
-  avg_latency=(int)(0.999*avg_latency+0.001*diff);
+  avg_latency=0.999*avg_latency+0.001*diff;
 }
 
 //! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for further processing
@@ -484,7 +484,7 @@ try
         cached.commitD(); // commit d to the packet                        inlined
         NS->send(cached); // answer it then                              inlined
         diff=question.d_dt.udiff();
-        avg_latency=(int)(0.999*avg_latency+0.001*diff); // 'EWMA'
+        avg_latency=0.999*avg_latency+0.001*diff; // 'EWMA'
         continue;
       }
     }
index 9ce7101b941a66ba7054d3d65fa000d7b48f7fcb..737ebb00f53af0b7a0593c8d1ec38a6c179df5cd 100644 (file)
@@ -43,7 +43,7 @@ extern std::unique_ptr<DynListener> dl;
 extern CommunicatorClass Communicator;
 extern std::shared_ptr<UDPNameserver> N;
 extern vector<std::shared_ptr<UDPNameserver> > g_udpReceivers;
-extern int avg_latency;
+extern double avg_latency;
 extern std::unique_ptr<TCPNameserver> TN;
 extern void declareArguments();
 extern void declareStats();