Changeset 535

Show
Ignore:
Timestamp:
11/02/05 15:27:31 (8 years ago)
Author:
ahu
Message:

fix pruning of negcache
specialize the common case where we see identical information coming in, and only update the ttd

Location:
trunk/pdns/pdns
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/Makefile.am

    r530 r535  
    4848 
    4949dnspbench_SOURCES=dnspbench.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \ 
    50         misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh 
     50        misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc logger.cc \ 
     51        statbag.cc 
    5152 
    5253 
  • trunk/pdns/pdns/dnspbench.cc

    r516 r535  
    44#include "dnswriter.hh" 
    55#include "dnsrecords.hh" 
     6#include "logger.hh" 
     7#include "statbag.hh" 
    68 
     9Logger L("dnspbench"); 
     10StatBag S; 
    711 
    812 
     
    1014try 
    1115{ 
     16  dnsheader dnsheader; 
     17  dnsheader.qdcount=htons(1); 
     18  dnsheader.ancount=htons(1); 
     19  Socket s(InterNetwork, Datagram); 
     20  string spacket; 
     21  char* p=(char*)&dnsheader; 
     22  spacket.assign(p, p+sizeof(dnsheader)); 
     23  IPEndpoint rem("127.0.0.1",5300); 
     24  s.sendTo(spacket, rem); 
     25   
     26  return 0; 
     27 
    1228  reportAllTypes(); 
    1329 
    14   cerr<<"sizeof(optString): "<<sizeof(struct optString)<<endl; 
     30  vector<uint8_t> packet; 
    1531 
    16   optString os("hallo!"); 
    17  
    18   cerr<<"optString: '"<<(string)os<<"'\n"; 
    19  
    20   vector<uint8_t> packet; 
    21    
    2232  uint16_t type=DNSRecordContent::TypeToNumber(argv[2]); 
    2333 
  • trunk/pdns/pdns/dnsreplay-mindex.cc

    r527 r535  
    512512        } 
    513513         
    514         double factor=20; 
     514        double factor=10; 
    515515         
    516516        seconds/=factor; 
     
    624624    gettimeofday(&now, 0); 
    625625 
    626     mental_time= mental_time + 2*(now-then); 
     626    mental_time= mental_time + 1*(now-then); 
    627627  } 
    628628 out:; 
  • trunk/pdns/pdns/pdns_recursor.cc

    r533 r535  
    501501  if(qcounter) { 
    502502    L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<RC.size()<<" cache entries, "<<SyncRes::s_negcache.size()<<" negative entries, " 
    503      <<(int)((RC.cacheHits*100.0)/(RC.cacheHits+RC.cacheMisses))<<"% cache hits"; 
    504     L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"; 
     503     <<(int)((RC.cacheHits*100.0)/(RC.cacheHits+RC.cacheMisses))<<"% cache hits"<<endl; 
     504    L<<Logger::Error<<"stats: throttle map: "<<SyncRes::s_throttle.size()<<", ns speeds: "<<SyncRes::s_nsSpeeds.size()<<endl; 
     505    L<<Logger::Error<<"stats: outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"; 
    505506    L<<Logger::Error<<", "<<(int)(SyncRes::s_throttledqueries*100.0/(SyncRes::s_outqueries+SyncRes::s_throttledqueries))<<"% throttled, " 
    506507     <<SyncRes::s_nodelegated<<" no-delegation drops"<<endl; 
     
    519520  if(now - last_prune > 60) {  
    520521    RC.doPrune(); 
     522    int pruned=0; 
     523    for(map<string, NegCacheEntry>::iterator i = SyncRes::s_negcache.begin(); i != SyncRes::s_negcache.end();)  
     524      if(i->second.ttd > now) { 
     525        SyncRes::s_negcache.erase(i++); 
     526        pruned++; 
     527      } 
     528      else 
     529        ++i; 
     530    //    cerr<<"Pruned "<<pruned<<" records, left "<<SyncRes::s_negcache.size()<<"\n"; 
    521531    last_prune=time(0); 
    522532  } 
  • trunk/pdns/pdns/recursor_cache.cc

    r534 r535  
    5959} 
    6060   
     61/* the code below is rather tricky - it basically replaces the stuff cached for qname by content, but it is special 
     62   cased for when inserting identical records with only differing ttls, in which case the entry is not 
     63   touched, but only given a new ttd */ 
    6164void MemRecursorCache::replace(const string &qname, const QType& qt,  const set<DNSResourceRecord>& content) 
    6265{ 
    6366  set<StoredRecord>& stored=d_cache[toLowerCanonic(qname)+"|"+qt.getName()]; 
    6467 
    65   for(set<StoredRecord>::iterator k=stored.begin();k!=stored.end();++k)  
    66     k->d_string.prune(); 
     68  set<StoredRecord>::iterator k; 
     69  typedef vector<set<StoredRecord>::iterator> touched_t; 
     70  touched_t touched; 
    6771 
    68   stored.clear(); 
     72  // walk through new content, encode it as new 
     73  StoredRecord dr; 
    6974 
    7075  for(set<DNSResourceRecord>::const_iterator i=content.begin(); i != content.end(); ++i) { 
    71     StoredRecord dr; 
    7276    dr.d_ttd=i->ttl; 
    7377    dr.d_string=DNSRR2String(*i); 
    74     stored.insert(dr); 
    75     //cerr<<"Storing: "<< toLowerCanonic(qname)+"|"+qt.getName() << " <=> '"<<i->content<<"', ttd="<<i->ttl<<endl; 
     78    k=stored.find(dr); 
     79    if(k!=stored.end()) {           // was it there already? 
     80      //      cerr<<"updating record '"<<qname<<"' -> '"<<i->content<<"'\n"; 
     81      k->d_ttd=i->ttl;              // update ttl 
     82      touched.push_back(k);         // note that this record is here to stay 
     83    } 
     84    else { 
     85      //      cerr<<"inserting record '"<<qname<<"' -> '"<<i->content<<"'\n"; 
     86      touched.push_back(stored.insert(dr).first);  // same thing 
     87    } 
     88  } 
     89 
     90  for(k=stored.begin(); k!=stored.end(); ) {                     // walk over the stored set of records 
     91    touched_t::const_iterator j;                                 
     92    for(j=touched.begin(); j!=touched.end() && *j != k ; ++j);   // walk over touched iterators 
     93    if(j==touched.end()) {                                       // this record was not there 
     94      //      DNSResourceRecord rr=String2DNSRR(qname, qt,  k->d_string, 0);  
     95      //      cerr<<"removing from record '"<<qname<<"' '"<<rr.content<<"'\n"; 
     96      k->d_string.prune();                                       
     97      stored.erase(k++);                                         // cleanup 
     98    } 
     99    else 
     100      ++k; 
    76101  } 
    77102} 
  • trunk/pdns/pdns/recursor_cache.hh

    r518 r535  
    7272  struct StoredRecord 
    7373  { 
    74     uint32_t d_ttd; 
     74    mutable uint32_t d_ttd; 
    7575    optString<> d_string; 
    7676    bool operator<(const StoredRecord& rhs) const 
    7777    { 
    78       return make_pair(d_ttd, d_string) < make_pair(rhs.d_ttd, rhs.d_string); 
     78      return d_string < rhs.d_string; 
     79      //      return make_pair(d_ttd, d_string) < make_pair(rhs.d_ttd, rhs.d_string); 
    7980    } 
    8081  }; 
    8182  typedef map<string, set<StoredRecord> > cache_t; 
    82  
     83private: 
    8384  cache_t d_cache; 
    8485}; 
  • trunk/pdns/pdns/syncres.cc

    r521 r535  
    3838 
    3939map<string,NegCacheEntry> SyncRes::s_negcache;     
     40map<string,DecayingEwma> SyncRes::s_nsSpeeds; 
    4041unsigned int SyncRes::s_queries; 
    4142unsigned int SyncRes::s_outgoingtimeouts; 
     
    230231      sqname=ni->second.name; 
    231232      sqt="SOA"; 
    232  
    233233    } 
    234234    else { 
     
    305305} 
    306306 
    307 static map<string,DecayingEwma> nsSpeeds; 
     307 
    308308 
    309309struct speedOrder 
     
    325325  for(set<string>::const_iterator i=nameservers.begin();i!=nameservers.end();++i) { 
    326326    rnameservers.push_back(*i); 
    327     DecayingEwma& temp=nsSpeeds[toLower(*i)]; 
     327    DecayingEwma& temp=s_nsSpeeds[toLower(*i)]; 
    328328    speeds[*i]=temp.get(&d_now); 
    329329  } 
     
    406406            LOG<<prefix<<qname<<": error resolving"<<endl; 
    407407 
    408           nsSpeeds[toLower(*tns)].submit(1000000, &d_now); // 1 sec 
     408          s_nsSpeeds[toLower(*tns)].submit(1000000, &d_now); // 1 sec 
    409409           
    410410          s_throttle.throttle(d_now.tv_sec, remoteIP+"|"+qname+"|"+qtype.getName(),20,5); 
     
    432432      } 
    433433      LOG<<prefix<<qname<<": Got "<<result.size()<<" answers from "<<*tns<<" ("<<remoteIP<<"), rcode="<<d_lwr.d_rcode<<", in "<<d_lwr.d_usec/1000<<"ms"<<endl; 
    434       nsSpeeds[toLower(*tns)].submit(d_lwr.d_usec, &d_now); 
     434      s_nsSpeeds[toLower(*tns)].submit(d_lwr.d_usec, &d_now); 
    435435 
    436436      map<string,set<DNSResourceRecord> > tcache; 
  • trunk/pdns/pdns/syncres.hh

    r469 r535  
    6565    else if(i->second.ttd > e.ttd || (i->second.count) < e.count)  
    6666      d_cont[t]=e; 
    67  
     67  } 
     68   
     69  unsigned int size() 
     70  { 
     71    return d_cont.size(); 
    6872  } 
    6973private: 
     
    165169  unsigned int d_timeouts; 
    166170  static map<string,NegCacheEntry> s_negcache;     
     171  static map<string,DecayingEwma> s_nsSpeeds; 
    167172  static Throttle<string> s_throttle; 
    168173private: