]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
implement patch from #424 improving ('fixing') our average latency calculation. Close...
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 27 May 2014 08:03:01 +0000 (10:03 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Tue, 27 May 2014 08:03:01 +0000 (10:03 +0200)
pdns/docs/pdns.xml
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/syncres.hh

index 425f0cc17a7268fdbe419f6166512e2d0bbc75c8..36ea4136066e4d50f6b19064c8128954d6e61a64 100644 (file)
@@ -14597,6 +14597,14 @@ sql> insert into domainmetadata (domain_id, kind, content) values (6, 'TSIG-ALLO
              </para>
            </listitem>
          </varlistentry>
+         <varlistentry>
+           <term>latency-statistic-size</term>
+           <listitem>
+             <para>
+               Indication of how many queries will be averaged to get the average latency reported by the 'qa-latency' metric. Since 3.6.
+             </para>
+           </listitem>
+         </varlistentry>
 
          <varlistentry>
            <term>local-address</term>
index b2a6608c15a163e14fafdcb231e83bfe66ec3894..e6f958d6bf2754462aa781711d741adccca8c906 100644 (file)
@@ -76,6 +76,7 @@ __thread FDMultiplexer* t_fdm;
 __thread unsigned int t_id;
 unsigned int g_maxTCPPerClient;
 unsigned int g_networkTimeoutMsec;
+uint64_t g_latencyStatSize;
 bool g_logCommonErrors;
 bool g_anyToTcp;
 uint16_t g_udpTruncationThreshold;
@@ -691,8 +692,8 @@ void startDoResolve(void *p)
       g_stats.answersSlow++;
 
     uint64_t newLat=(uint64_t)(spent*1000000);
-    if(newLat < 1000000)  // outliers of several minutes exist..
-      g_stats.avgLatencyUsec=(uint64_t)((1-0.0001)*g_stats.avgLatencyUsec + 0.0001*newLat);
+    newLat = min(newLat,(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;
 
     delete dc;
     dc=0;
@@ -884,7 +885,7 @@ string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fr
         memcpy(&dh, response.c_str(), sizeof(dh));
         updateRcodeStats(dh.rcode);
       }
-      g_stats.avgLatencyUsec=(uint64_t)((1-0.0001)*g_stats.avgLatencyUsec + 0); // we assume 0 usec
+      g_stats.avgLatencyUsec=(1-1.0/g_latencyStatSize)*g_stats.avgLatencyUsec + 0.0; // we assume 0 usec
       return 0;
     }
   } 
@@ -1850,6 +1851,7 @@ int serviceMain(int argc, char*argv[])
 
   g_initialDomainMap = parseAuthAndForwards();
  
+  g_latencyStatSize=::arg().asNum("latency-statistic-size");
     
   g_logCommonErrors=::arg().mustDo("log-common-errors");
 
@@ -2149,6 +2151,7 @@ int main(int argc, char **argv)
     ::arg().set("etc-hosts-file", "Path to 'hosts' file")="/etc/hosts";
     ::arg().set("serve-rfc1918", "If we should be authoritative for RFC 1918 private IP space")="";
     ::arg().set("lua-dns-script", "Filename containing an optional 'lua' script that will be used to modify dns answers")="";
+    ::arg().set("latency-statistic-size","Number of latency values to calculate the qa-latency average")="10000";
 //    ::arg().setSwitch( "disable-edns-ping", "Disable EDNSPing - EXPERIMENTAL, LEAVE DISABLED" )= "no"; 
     ::arg().setSwitch( "disable-edns", "Disable EDNS - EXPERIMENTAL, LEAVE DISABLED" )= ""; 
     ::arg().setSwitch( "disable-packetcache", "Disable packetcache" )= "no"; 
index 207da8186e5f7d7dedf4cd7e2aabdfc284e2b1b6..d1e6e3d1a3c77b4f3f58b006930dd3cf67d677be 100644 (file)
@@ -369,6 +369,12 @@ uint64_t doGetCacheSize()
   return broadcastAccFunction<uint64_t>(pleaseGetCacheSize);
 }
 
+uint64_t doGetAvgLatencyUsec()
+{
+  return (uint64_t) g_stats.avgLatencyUsec;
+}
+
+
 uint64_t doGetCacheBytes()
 {
   return broadcastAccFunction<uint64_t>(pleaseGetCacheBytes);
@@ -487,7 +493,7 @@ RecursorControlParser::RecursorControlParser()
   addGetStat("answers100-1000", &g_stats.answers100_1000);
   addGetStat("answers-slow", &g_stats.answersSlow);
 
-  addGetStat("qa-latency", &g_stats.avgLatencyUsec);
+  addGetStat("qa-latency", doGetAvgLatencyUsec);
   addGetStat("unexpected-packets", &g_stats.unexpectedCount);
   addGetStat("case-mismatches", &g_stats.caseMismatchCount);
   addGetStat("spoof-prevents", &g_stats.spoofCount);
index 4c855b01d50bd639837df6bebe6a24f691a46e9a..6497fb40b797880f714c5d4fcc85c8ae0b0646e4 100644 (file)
@@ -546,7 +546,7 @@ struct RecursorStats
   uint64_t nxDomains;
   uint64_t noErrors;
   uint64_t answers0_1, answers1_10, answers10_100, answers100_1000, answersSlow;
-  uint64_t avgLatencyUsec;
+  double avgLatencyUsec;
   uint64_t qcounter;
   uint64_t ipv6qcounter;
   uint64_t tcpqcounter;