Skip to content

Commit

Permalink
implement patch from #424 improving ('fixing') our average latency ca…
Browse files Browse the repository at this point in the history
…lculation. Closes #424.
  • Loading branch information
ahupowerdns committed May 27, 2014
1 parent 7710cc5 commit 08f3f63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pdns/docs/pdns.xml
Expand Up @@ -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>
Expand Down
9 changes: 6 additions & 3 deletions pdns/pdns_recursor.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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";
Expand Down
8 changes: 7 additions & 1 deletion pdns/rec_channel_rec.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pdns/syncres.hh
Expand Up @@ -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;
Expand Down

0 comments on commit 08f3f63

Please sign in to comment.