From 6fd633bedd35a36f868e9d1a30d38d983512ffc3 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Tue, 24 Nov 2020 20:50:34 +0100 Subject: [PATCH] auth: fix rounding inaccuracy in latency statistics --- pdns/common_startup.cc | 8 ++++---- pdns/common_startup.hh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 437ca3f708..fa00fb1d9f 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -58,7 +58,7 @@ std::unique_ptr DP{nullptr}; std::unique_ptr dl{nullptr}; CommunicatorClass Communicator; shared_ptr N; -int avg_latency; +double avg_latency{0.0}; unique_ptr TN; static vector g_distributors; vector > 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& 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; } } diff --git a/pdns/common_startup.hh b/pdns/common_startup.hh index 9ce7101b94..737ebb00f5 100644 --- a/pdns/common_startup.hh +++ b/pdns/common_startup.hh @@ -43,7 +43,7 @@ extern std::unique_ptr dl; extern CommunicatorClass Communicator; extern std::shared_ptr N; extern vector > g_udpReceivers; -extern int avg_latency; +extern double avg_latency; extern std::unique_ptr TN; extern void declareArguments(); extern void declareStats(); -- 2.47.2