From: Bert Hubert Date: Sun, 19 Mar 2006 19:57:15 +0000 (+0000) Subject: add per query latency accounting. WARNING: DTime from now on does implicit set()... X-Git-Tag: rec-3-0~151 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe213470a78c544f3960c1ba796c74520f506a06;p=pdns add per query latency accounting. WARNING: DTime from now on does implicit set() on udiff()! Needed for previous commit git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@602 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/misc.hh b/pdns/misc.hh index 5c027bc54..17b1f4350 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -160,10 +160,11 @@ inline void DTime::set() inline int DTime::udiff() { struct timeval now; - // Utility:: - gettimeofday(&now,0); - return 1000000*(now.tv_sec-d_set.tv_sec)+(now.tv_usec-d_set.tv_usec); + gettimeofday(&now,0); + int ret=1000000*(now.tv_sec-d_set.tv_sec)+(now.tv_usec-d_set.tv_usec); + d_set=now; + return ret; } inline bool dns_isspace(char c) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 32cb259e0..2a0e7d02d 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -328,6 +328,18 @@ void startDoResolve(void *p) } sr.d_outqueries ? RC.cacheMisses++ : RC.cacheHits++; + float spent=makeFloat(sr.d_now-dc->d_now); + if(spent < 0.001) + g_stats.answers0_1++; + else if(spent < 0.010) + g_stats.answers1_10++; + else if(spent < 0.1) + g_stats.answers10_100++; + else if(spent < 1.0) + g_stats.answers100_1000++; + else + g_stats.answersSlow++; + delete dc; } catch(AhuException &ae) { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index f21ff206e..317c2c2ae 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -84,6 +84,13 @@ RecursorControlParser::RecursorControlParser() addGetStat("servfail-answers", &g_stats.servFails); addGetStat("nxdomain-answers", &g_stats.nxDomains); addGetStat("noerror-answers", &g_stats.noErrors); + + addGetStat("answers0-1", &g_stats.answers0_1); + addGetStat("answers1-10", &g_stats.answers1_10); + addGetStat("answers10-100", &g_stats.answers10_100); + addGetStat("answers100-1000", &g_stats.answers100_1000); + addGetStat("answers-slow", &g_stats.answersSlow); + addGetStat("all-questions", &qcounter); addGetStat("negcache-entries", bind(&SyncRes::negcache_t::size, ref(SyncRes::s_negcache))); addGetStat("throttle-entries", bind(&SyncRes::throttle_t::size, ref(SyncRes::s_throttle))); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 8f83eefa3..2914cac67 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -209,8 +209,8 @@ private: class SyncRes { public: - explicit SyncRes(const struct timeval& now) : d_outqueries(0), d_tcpoutqueries(0), d_throttledqueries(0), d_timeouts(0), - d_cacheonly(false), d_nocache(false), d_now(now) { } + explicit SyncRes(const struct timeval& now) : d_outqueries(0), d_tcpoutqueries(0), d_throttledqueries(0), d_timeouts(0), d_now(now), + d_cacheonly(false), d_nocache(false) { } int beginResolve(const string &qname, const QType &qtype, vector&ret); void setId(int id) { @@ -247,6 +247,7 @@ public: typedef Throttle throttle_t; static throttle_t s_throttle; + struct timeval d_now; private: struct GetBestNSAnswer; int doResolveAt(set nameservers, string auth, const string &qname, const QType &qtype, vector&ret, @@ -265,13 +266,14 @@ private: SyncRes(const SyncRes&); SyncRes& operator=(const SyncRes&); + + private: string d_prefix; static bool s_log; bool d_cacheonly; bool d_nocache; LWRes d_lwr; - struct timeval d_now; struct GetBestNSAnswer { @@ -328,6 +330,7 @@ struct RecursorStats uint64_t nxDomains; uint64_t noErrors; PulseRate queryrate; + uint64_t answers0_1, answers1_10, answers10_100, answers100_1000, answersSlow; }; extern RecursorStats g_stats;