]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Avoid some uint64_t vs double confusion and make sure we write stats
authorOtto <otto.moerbeek@open-xchange.com>
Tue, 16 Feb 2021 13:00:29 +0000 (14:00 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Fri, 19 Feb 2021 09:26:33 +0000 (10:26 +0100)
data in an atomic way.

pdns/misc.hh
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/syncres.hh

index 7998623e24b3ab3e3d5553b3356cf8181f76fe5a..a6c926da70a497707107bf291e49665db16e0e8b 100644 (file)
@@ -312,6 +312,10 @@ inline float makeFloat(const struct timeval& tv)
 {
   return tv.tv_sec + tv.tv_usec/1000000.0f;
 }
+inline double makeDouble(const struct timeval& tv)
+{
+  return tv.tv_sec + tv.tv_usec/1000000.0;
+}
 
 inline bool operator<(const struct timeval& lhs, const struct timeval& rhs)
 {
index 440e898167b011db0fc53b9bf6948629ada32420..c330997aa55e501cd8b02a8600bc7021a894b973 100644 (file)
@@ -2142,7 +2142,7 @@ static void startDoResolve(void *p)
       finishTCPReply(dc, hadError, true);
     }
 
-    float spent=makeFloat(sr.getNow()-dc->d_now);
+    double spent = makeDouble(sr.getNow() - dc->d_now);
     if (!g_quiet) {
       g_log<<Logger::Error<<t_id<<" ["<<MT->getTid()<<"/"<<MT->numProcesses()<<"] answer to "<<(dc->d_mdp.d_header.rd?"":"non-rd ")<<"question '"<<dc->d_mdp.d_qname<<"|"<<DNSRecordContent::NumberToType(dc->d_mdp.d_qtype);
       g_log<<"': "<<ntohs(pw.getHeader()->ancount)<<" answers, "<<ntohs(pw.getHeader()->arcount)<<" additional, took "<<sr.d_outqueries<<" packets, "<<
@@ -2162,9 +2162,9 @@ static void startDoResolve(void *p)
       g_recCache->cacheHits++;
     }
 
-    if(spent < 0.001)
+    if (spent < 0.001)
       g_stats.answers0_1++;
-    else if(spent < 0.010)
+    else if(spent < 0.01)
       g_stats.answers1_10++;
     else if(spent < 0.1)
       g_stats.answers10_100++;
@@ -2173,12 +2173,12 @@ static void startDoResolve(void *p)
     else
       g_stats.answersSlow++;
 
-    uint64_t newLat=(uint64_t)(spent*static_cast<uint64_t>(1000000));
-    newLat = min(newLat,(uint64_t)(((uint64_t) g_networkTimeoutMsec)*1000)); // outliers of several minutes exist..
-    g_stats.avgLatencyUsec=(1-1.0/g_latencyStatSize)*g_stats.avgLatencyUsec + (float)newLat/g_latencyStatSize;
+    double newLat = spent * 1000000.0;
+    newLat = min(newLat, g_networkTimeoutMsec * 1000.0); // outliers of several minutes exist..
+    g_stats.avgLatencyUsec = (1.0 - 1.0 / g_latencyStatSize) * g_stats.avgLatencyUsec + newLat / g_latencyStatSize;
     // no worries, we do this for packet cache hits elsewhere
 
-    auto ourtime = 1000.0*spent-sr.d_totUsec/1000.0; // in msec
+    double ourtime = 1000.0 * spent - sr.d_totUsec / 1000.0; // in msec
     if(ourtime < 1)
       g_stats.ourtime0_1++;
     else if(ourtime < 2)
@@ -2192,12 +2192,12 @@ static void startDoResolve(void *p)
     else if(ourtime < 32)
       g_stats.ourtime16_32++;
     else {
-      //      cerr<<"SLOW: "<<ourtime<<"ms -> "<<dc->d_mdp.d_qname<<"|"<<DNSRecordContent::NumberToType(dc->d_mdp.d_qtype)<<endl;
       g_stats.ourtimeSlow++;
     }
-    if(ourtime >= 0.0) {
-      newLat=ourtime*1000; // usec
-      g_stats.avgLatencyOursUsec=(1-1.0/g_latencyStatSize)*g_stats.avgLatencyOursUsec + (float)newLat/g_latencyStatSize;
+
+    if (ourtime >= 0) {
+      newLat = ourtime * 1000.0; // usec
+      g_stats.avgLatencyOursUsec = (1.0 - 1.0 / g_latencyStatSize) * g_stats.avgLatencyOursUsec + newLat / g_latencyStatSize;
     }
 
 #ifdef NOD_ENABLED
index 0bcc47238eb868c6db0cd04edf132837a426626d..78a08b7c5fcc551660e8006ff1e649666a243f92 100644 (file)
@@ -1103,7 +1103,7 @@ static void registerAllStats1()
 
 
   addGetStat("qa-latency", doGetAvgLatencyUsec);
-  addGetStat("x-our-latency", []() { return g_stats.avgLatencyOursUsec; });
+  addGetStat("x-our-latency", []() { return g_stats.avgLatencyOursUsec.load(); });
   addGetStat("unexpected-packets", &g_stats.unexpectedCount);
   addGetStat("case-mismatches", &g_stats.caseMismatchCount);
   addGetStat("spoof-prevents", &g_stats.spoofCount);
index abf4eaf8bf1b96a39b1dc2f8b90bf79c97e27525..7632e322c027dd64ec0bb68f9a2a5971e71e0573 100644 (file)
@@ -980,8 +980,8 @@ struct RecursorStats
   std::atomic<uint64_t> auth4Answers0_1, auth4Answers1_10, auth4Answers10_100, auth4Answers100_1000, auth4AnswersSlow;
   std::atomic<uint64_t> auth6Answers0_1, auth6Answers1_10, auth6Answers10_100, auth6Answers100_1000, auth6AnswersSlow;
   std::atomic<uint64_t> ourtime0_1, ourtime1_2, ourtime2_4, ourtime4_8, ourtime8_16, ourtime16_32, ourtimeSlow;
-  double avgLatencyUsec{0};
-  double avgLatencyOursUsec{0};
+  std::atomic<double> avgLatencyUsec;
+  std::atomic<double> avgLatencyOursUsec;
   std::atomic<uint64_t> qcounter;     // not increased for unauth packets
   std::atomic<uint64_t> ipv6qcounter;
   std::atomic<uint64_t> tcpqcounter;