From: Kees Monshouwer Date: Tue, 24 Nov 2020 19:50:34 +0000 (+0100) Subject: auth: fix rounding inaccuracy in latency statistics X-Git-Tag: rec-4.5.0-alpha1~94^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fd633bedd35a36f868e9d1a30d38d983512ffc3;p=thirdparty%2Fpdns.git auth: fix rounding inaccuracy in latency statistics --- 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();