Changeset 628

Show
Ignore:
Timestamp:
03/26/06 12:51:55 (7 years ago)
Author:
ahu
Message:

move negcache to boost::multi_index, make sure it gets pruned a bit faster. Also, and this is controversial, cap SOA negative caching to 3600 seconds.
This is done for two reasons: 1) the cache grows HUGE otherwise 2) I'm pretty sure anything >3600 seconds will annoy people
a lot.

Location:
trunk/pdns/pdns
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/mtasker.cc

    r596 r628  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2002 - 2005  PowerDNS.COM BV 
     3    Copyright (C) 2002 - 2006  PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
    6     it under the terms of the GNU General Public License as published by 
    7     the Free Software Foundation; either version 2 of the License, or 
    8     (at your option) any later version. 
     6    it under the terms of the GNU General Public License version 2 as  
     7    published by the Free Software Foundation 
    98 
    109    This program is distributed in the hope that it will be useful, 
  • trunk/pdns/pdns/pdns_recursor.cc

    r627 r628  
    4949#include "rec_channel.hh" 
    5050 
    51 // using namespace boost; 
     51using namespace boost; 
    5252 
    5353#ifdef __FreeBSD__           // see cvstrac ticket #26 
     
    546546    RC.doPrune(); 
    547547    int pruned=0; 
    548     for(SyncRes::negcache_t::iterator i = SyncRes::s_negcache.begin(); i != SyncRes::s_negcache.end();)  
    549       if(i->second.ttd < now.tv_sec) { 
    550         SyncRes::s_negcache.erase(i++); 
    551         pruned++; 
    552       } 
    553       else 
    554         ++i; 
     548     
     549    typedef SyncRes::negcache_t::nth_index<1>::type negcache_by_ttd_index_t; 
     550    negcache_by_ttd_index_t& ttdindex=boost::multi_index::get<1>(SyncRes::s_negcache); 
     551 
     552    negcache_by_ttd_index_t::iterator i=ttdindex.lower_bound(now.tv_sec); 
     553    ttdindex.erase(ttdindex.begin(), i); 
    555554 
    556555    time_t limit=now.tv_sec-300; 
  • trunk/pdns/pdns/rec_channel_rec.cc

    r625 r628  
    112112  addGetStat("cache-misses", &RC.cacheMisses); 
    113113 
    114   addGetStat("cache-entries", bind(&MemRecursorCache::size, ref(RC))); 
     114  addGetStat("cache-entries", boost::bind(&MemRecursorCache::size, ref(RC))); 
    115115  addGetStat("servfail-answers", &g_stats.servFails); 
    116116  addGetStat("nxdomain-answers", &g_stats.nxDomains); 
     
    126126 
    127127  addGetStat("all-questions", &qcounter); 
    128   addGetStat("negcache-entries", bind(&SyncRes::negcache_t::size, ref(SyncRes::s_negcache))); 
    129   addGetStat("throttle-entries", bind(&SyncRes::throttle_t::size, ref(SyncRes::s_throttle))); 
    130   addGetStat("nsspeeds-entries", bind(&SyncRes::nsspeeds_t::size, ref(SyncRes::s_nsSpeeds))); 
     128  addGetStat("negcache-entries", boost::bind(&SyncRes::negcache_t::size, ref(SyncRes::s_negcache))); 
     129  addGetStat("throttle-entries", boost::bind(&SyncRes::throttle_t::size, ref(SyncRes::s_throttle))); 
     130  addGetStat("nsspeeds-entries", boost::bind(&SyncRes::nsspeeds_t::size, ref(SyncRes::s_nsSpeeds))); 
    131131 
    132   addGetStat("concurrent-queries", bind(&MTasker<PacketID,string>::numProcesses, ref(MT))); 
     132  addGetStat("concurrent-queries", boost::bind(&MTasker<PacketID,string>::numProcesses, ref(MT))); 
    133133  addGetStat("outgoing-timeouts", &SyncRes::s_outgoingtimeouts); 
    134134  addGetStat("tcp-outqueries", &SyncRes::s_tcpoutqueries); 
  • trunk/pdns/pdns/syncres.cc

    r624 r628  
    249249  uint32_t sttl=0; 
    250250 
    251   if(s_negcache.count(toLower(qname))) { 
     251  negcache_t::iterator ni=s_negcache.find(toLower(qname)); 
     252  if(ni!=s_negcache.end()) { 
     253    cerr<<"found something\n"; 
    252254    res=0; 
    253     negcache_t::const_iterator ni=s_negcache.find(toLower(qname)); 
    254     if(d_now.tv_sec < ni->second.ttd) { 
    255       sttl=ni->second.ttd - d_now.tv_sec; 
     255    if((uint32_t)d_now.tv_sec < ni->d_ttd) { 
     256      sttl=ni->d_ttd - d_now.tv_sec; 
    256257      LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl; 
    257258      res=RCode::NXDomain;  
    258259      giveNegative=true; 
    259       sqname=ni->second.name; 
     260      sqname=ni->d_qname; 
    260261      sqt="SOA"; 
    261262    } 
    262263    else { 
    263264      LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"' was negatively cached, but entry expired"<<endl; 
    264       s_negcache.erase(toLower(qname)); 
     265      s_negcache.erase(ni); 
    265266    } 
    266267  } 
     
    271272 
    272273    res=0; 
    273     negcache_t::const_iterator ni=s_negcache.find(tuple); 
     274    ni=s_negcache.find(tuple); 
    274275    if(ni!=s_negcache.end()) { 
    275       if(d_now.tv_sec < ni->second.ttd) { 
    276         sttl=ni->second.ttd - d_now.tv_sec; 
     276      if((uint32_t)d_now.tv_sec < ni->d_ttd) { 
     277        sttl=ni->d_ttd - d_now.tv_sec; 
    277278        LOG<<prefix<<qname<<": "<<qtype.getName()<<" is negatively cached for another "<<sttl<<" seconds"<<endl; 
    278279        res=RCode::NoError; // only this record doesn't exist 
    279280        giveNegative=true; 
    280         sqname=ni->second.name; 
     281        sqname=ni->d_qname; 
    281282        sqt="SOA"; 
    282283      } 
    283284      else { 
    284285        LOG<<prefix<<qname<<": "<<qtype.getName()<<" was negatively cached, but entry expired"<<endl; 
    285         s_negcache.erase(toLower(tuple)); 
     286        s_negcache.erase(ni); 
    286287      } 
    287288    } 
     
    529530 
    530531          NegCacheEntry ne; 
    531           ne.name=i->qname; 
    532           ne.ttd=d_now.tv_sec + i->ttl; 
    533           s_negcache[toLower(qname)]=ne; 
     532 
     533          ne.d_qname=i->qname; 
     534          ne.d_ttd=d_now.tv_sec + min(i->ttl, 3600U); // controversial 
     535          ne.d_name=toLower(qname); 
     536          s_negcache.insert(ne); 
    534537          negindic=true; 
    535538        } 
     
    568571           
    569572          NegCacheEntry ne; 
    570           ne.name=i->qname; 
    571           ne.ttd=d_now.tv_sec + i->ttl; 
    572           s_negcache[toLower(qname)+"|"+qtype.getName()]=ne; 
     573          ne.d_qname=i->qname; 
     574          ne.d_ttd=d_now.tv_sec + min(3600U,i->ttl); 
     575          ne.d_name=toLower(qname)+"|"+qtype.getName(); 
     576          s_negcache.insert(ne); 
    573577          negindic=true; 
    574578        } 
  • trunk/pdns/pdns/syncres.hh

    r619 r628  
    2626struct NegCacheEntry 
    2727{ 
    28   string name; 
    29   time_t ttd; 
     28  string d_qname; 
     29  string d_name; 
     30  uint32_t d_ttd; 
    3031}; 
    3132 
     
    241242  unsigned int d_throttledqueries; 
    242243  unsigned int d_timeouts; 
    243   typedef map<string,NegCacheEntry> negcache_t; 
     244  //  typedef map<string,NegCacheEntry> negcache_t; 
     245 
     246  typedef multi_index_container < 
     247    NegCacheEntry, 
     248    indexed_by < 
     249       ordered_unique< 
     250           member<NegCacheEntry, string, &NegCacheEntry::d_name> 
     251       >, 
     252       ordered_non_unique< 
     253           member<NegCacheEntry, uint32_t, &NegCacheEntry::d_ttd> 
     254       > 
     255    > 
     256  >negcache_t; 
    244257  static negcache_t s_negcache;     
    245258