From 9fdf67d56af4d5635b0bb4f6b82c594c11e8ade6 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 11 Nov 2005 11:41:39 +0000 Subject: [PATCH] move to 'floats' for nameserver statistics - we don't need 80 bits of precision! remove some spurious logging that was slowing powerdns down - logging that would never be displayed parametrise namesever stats and query throttling for possible move to other containers add support for pruning these stats git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@543 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/syncres.cc | 22 +++++++++++++--------- pdns/syncres.hh | 37 ++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 6efa21dd0..890d0641d 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -36,8 +36,9 @@ extern MemRecursorCache RC; -map SyncRes::s_negcache; -map SyncRes::s_nsSpeeds; +SyncRes::negcache_t SyncRes::s_negcache; +SyncRes::nsspeeds_t SyncRes::s_nsSpeeds; + unsigned int SyncRes::s_queries; unsigned int SyncRes::s_outgoingtimeouts; unsigned int SyncRes::s_outqueries; @@ -129,12 +130,15 @@ void SyncRes::getBestNSFromCache(const string &qname, set&bes rr.content=toLowerCanonic(k->content); if(!endsOn(rr.content,subdomain) || RC.get(d_now.tv_sec, rr.content ,QType(QType::A),&aset) > 5) { bestns.insert(rr); + LOG< '"<content)<<") which we miss or is expired"<::const_iterator ni=s_negcache.find(toLower(qname)); + negcache_t::const_iterator ni=s_negcache.find(toLower(qname)); if(d_now.tv_sec < ni->second.ttd) { sttl=ni->second.ttd - d_now.tv_sec; LOG<::const_iterator ni=s_negcache.find(tuple); + negcache_t::const_iterator ni=s_negcache.find(tuple); if(ni!=s_negcache.end()) { if(d_now.tv_sec < ni->second.ttd) { sttl=ni->second.ttd - d_now.tv_sec; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index edd87eb69..58e71f140 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -12,6 +12,7 @@ #include "misc.hh" #include "lwres.hh" #include +#include "recursor_cache.hh" /* external functions, opaque to us */ @@ -102,37 +103,42 @@ public: void submit(int val, struct timeval*tv = 0) { - double now; + float now; if(tv) now=tv->tv_sec + tv->tv_usec/1000000.0; else now=getTime(); - double diff=d_last-now; + float diff=d_last-now; d_last=now; - double factor=exp(diff)/2.0; // might be '0.5', or 0.0001 + float factor=exp(diff)/2.0; // might be '0.5', or 0.0001 d_val=(1-factor)*val+ factor*d_val; } - double get(struct timeval*tv = 0) + float get(struct timeval*tv = 0) { - double now; + float now; if(tv) now=tv->tv_sec + tv->tv_usec/1000000.0; else now=getTime(); - double diff=d_lastget-now; + float diff=d_lastget-now; d_lastget=now; - double factor=exp(diff/60.0); // is 1.0 or less + float factor=exp(diff/60.0); // is 1.0 or less return d_val*=factor; } + bool stale(time_t limit) + { + return limit > d_lastget; + } + private: DecayingEwma& operator=(const DecayingEwma&); - double d_last; - double d_lastget; - double d_val; + float d_last; + float d_lastget; + float d_val; }; @@ -143,7 +149,8 @@ public: int beginResolve(const string &qname, const QType &qtype, vector&ret); void setId(int id) { - d_prefix="["+itoa(id)+"] "; + if(s_log) + d_prefix="["+itoa(id)+"] "; } static void setLog(bool log) { @@ -167,8 +174,12 @@ public: unsigned int d_tcpoutqueries; unsigned int d_throttledqueries; unsigned int d_timeouts; - static map s_negcache; - static map s_nsSpeeds; + typedef map negcache_t; + static negcache_t s_negcache; + + typedef map nsspeeds_t; + static nsspeeds_t s_nsSpeeds; + static Throttle s_throttle; private: struct GetBestNSAnswer; -- 2.49.0