]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
move to 'floats' for nameserver statistics - we don't need 80 bits of precision!
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 11 Nov 2005 11:41:39 +0000 (11:41 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 11 Nov 2005 11:41:39 +0000 (11:41 +0000)
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
pdns/syncres.hh

index 6efa21dd053a27bf08d873485a17f449bee767bb..890d0641d9d2047addd8e2b70d2d3e6013fb959a 100644 (file)
@@ -36,8 +36,9 @@
 
 extern MemRecursorCache RC;
 
-map<string,NegCacheEntry> SyncRes::s_negcache;    
-map<string,DecayingEwma> 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<DNSResourceRecord>&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<<prefix<<qname<<": NS (with ip, or non-glue) in cache for '"<<subdomain<<"' -> '"<<rr.content<<"'"<<endl;
            LOG<<prefix<<qname<<": within bailiwick: "<<endsOn(rr.content,subdomain);
-           if(!aset.empty())
-             L<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now.tv_sec ))<<endl;
-           else
-             L<<", not in cache"<<endl;
+           if(!aset.empty()) {
+             LOG<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now.tv_sec ))<<endl;
+           }
+           else {
+             LOG<<", not in cache"<<endl;
+           }
          }
          else
            LOG<<prefix<<qname<<": NS in cache for '"<<subdomain<<"', but needs glue ("<<toLowerCanonic(k->content)<<") which we miss or is expired"<<endl;
@@ -222,7 +226,7 @@ bool SyncRes::doCacheCheck(const string &qname, const QType &qtype, vector<DNSRe
 
   if(s_negcache.count(toLower(qname))) {
     res=0;
-    map<string,NegCacheEntry>::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<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl;
@@ -238,11 +242,11 @@ bool SyncRes::doCacheCheck(const string &qname, const QType &qtype, vector<DNSRe
   }
 
   if(!giveNegative) { // let's try some more
-    tuple=toLower(qname)+"|"+qtype.getName();
+    tuple=toLower(qname); tuple.append(1,'|'); tuple+=qtype.getName();
     LOG<<prefix<<qname<<": Looking for direct cache hit of '"<<tuple<<"', negative cached: "<<s_negcache.count(tuple)<<endl;
 
     res=0;
-    map<string,NegCacheEntry>::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;
index edd87eb69bce36445ae296f0f55ad960711e2264..58e71f14042a888e384a448ad86c7cbac284ed87 100644 (file)
@@ -12,6 +12,7 @@
 #include "misc.hh"
 #include "lwres.hh"
 #include <boost/utility.hpp>
+#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<DNSResourceRecord>&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<string,NegCacheEntry> s_negcache;    
-  static map<string,DecayingEwma> s_nsSpeeds;
+  typedef map<string,NegCacheEntry> negcache_t;
+  static negcache_t s_negcache;    
+
+  typedef map<string,DecayingEwma> nsspeeds_t;
+  static nsspeeds_t s_nsSpeeds;
+
   static Throttle<string> s_throttle;
 private:
   struct GetBestNSAnswer;