Permalink
Browse files

implement patch from #424 improving ('fixing') our average latency ca…

…lculation. Closes #424.
  • Loading branch information...
1 parent 7710cc5 commit 08f3f638e3e5f3a71f66dbe6a9f7ea91fa157a86 @ahupowerdns ahupowerdns committed May 27, 2014
Showing with 22 additions and 5 deletions.
  1. +8 −0 pdns/docs/pdns.xml
  2. +6 −3 pdns/pdns_recursor.cc
  3. +7 −1 pdns/rec_channel_rec.cc
  4. +1 −1 pdns/syncres.hh
View
@@ -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>
@@ -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";
@@ -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);
View
@@ -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;

0 comments on commit 08f3f63

Please sign in to comment.