From 08f3f638e3e5f3a71f66dbe6a9f7ea91fa157a86 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 27 May 2014 10:03:01 +0200 Subject: [PATCH] implement patch from #424 improving ('fixing') our average latency calculation. Closes #424. --- pdns/docs/pdns.xml | 8 ++++++++ pdns/pdns_recursor.cc | 9 ++++++--- pdns/rec_channel_rec.cc | 8 +++++++- pdns/syncres.hh | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pdns/docs/pdns.xml b/pdns/docs/pdns.xml index 425f0cc17..36ea41360 100644 --- a/pdns/docs/pdns.xml +++ b/pdns/docs/pdns.xml @@ -14597,6 +14597,14 @@ sql> insert into domainmetadata (domain_id, kind, content) values (6, 'TSIG-ALLO + + latency-statistic-size + + + Indication of how many queries will be averaged to get the average latency reported by the 'qa-latency' metric. Since 3.6. + + + local-address diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index b2a6608c1..e6f958d6b 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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"; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 207da8186..d1e6e3d1a 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -369,6 +369,12 @@ uint64_t doGetCacheSize() return broadcastAccFunction(pleaseGetCacheSize); } +uint64_t doGetAvgLatencyUsec() +{ + return (uint64_t) g_stats.avgLatencyUsec; +} + + uint64_t doGetCacheBytes() { return broadcastAccFunction(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); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 4c855b01d..6497fb40b 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -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; -- 2.40.0