Changeset 469
- Timestamp:
- 09/02/05 16:53:40 (8 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 3 modified
-
pdns_recursor.cc (modified) (1 diff)
-
syncres.cc (modified) (15 diffs)
-
syncres.hh (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/pdns_recursor.cc
r464 r469 483 483 }; 484 484 485 #if 0 486 487 #include <execinfo.h> 488 489 static void maketrace() 490 { 491 void *array[20]; //only care about last 17 functions (3 taken with tracing support) 492 size_t size; 493 char **strings; 494 size_t i; 495 496 size = backtrace (array, 20); 497 strings = backtrace_symbols (array, size); //Need -rdynamic gcc (linker) flag for this to work 498 499 for (i = 0; i < size; i++) //skip useless functions 500 cout<<strings[i]<<"\n"; 501 cout<<"--"<<endl; 502 } 503 504 extern "C" { 505 int gettimeofday (struct timeval *__restrict __tv, 506 __timezone_ptr_t __tz) 507 { 508 maketrace(); 509 return 0; 510 } 511 512 } 513 #endif 514 485 515 int main(int argc, char **argv) 486 516 { -
trunk/pdns/pdns/syncres.cc
r440 r469 118 118 LOG<<prefix<<qname<<": Checking if we have NS in cache for '"<<subdomain<<"'"<<endl; 119 119 set<DNSResourceRecord>ns; 120 if(RC.get(d_now , subdomain,QType(QType::NS),&ns)>0) {120 if(RC.get(d_now.tv_sec, subdomain,QType(QType::NS),&ns)>0) { 121 121 122 122 for(set<DNSResourceRecord>::const_iterator k=ns.begin();k!=ns.end();++k) { 123 if(k->ttl > (unsigned int)d_now ) {123 if(k->ttl > (unsigned int)d_now.tv_sec ) { 124 124 set<DNSResourceRecord>aset; 125 if(!endsOn(k->content,subdomain) || RC.get(d_now , k->content,QType(QType::A),&aset) > 5) {125 if(!endsOn(k->content,subdomain) || RC.get(d_now.tv_sec, k->content,QType(QType::A),&aset) > 5) { 126 126 bestns.insert(*k); 127 127 LOG<<prefix<<qname<<": NS (with ip, or non-glue) in cache for '"<<subdomain<<"' -> '"<<k->content<<"'"<<endl; 128 128 LOG<<prefix<<qname<<": within bailiwick: "<<endsOn(k->content,subdomain); 129 129 if(!aset.empty()) 130 L<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now ))<<endl;130 L<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now.tv_sec ))<<endl; 131 131 else 132 132 L<<", not in cache"<<endl; … … 184 184 LOG<<prefix<<qname<<": Looking for CNAME cache hit of '"<<tuple<<"'"<<endl; 185 185 set<DNSResourceRecord> cset; 186 if(RC.get(d_now , qname,QType(QType::CNAME),&cset) > 0) {186 if(RC.get(d_now.tv_sec, qname,QType(QType::CNAME),&cset) > 0) { 187 187 188 188 for(set<DNSResourceRecord>::const_iterator j=cset.begin();j!=cset.end();++j) { 189 if(j->ttl>(unsigned int) d_now ) {189 if(j->ttl>(unsigned int) d_now.tv_sec) { 190 190 LOG<<prefix<<qname<<": Found cache CNAME hit for '"<<tuple<<"' to '"<<j->content<<"'"<<endl; 191 191 DNSResourceRecord rr=*j; 192 rr.ttl-=d_now ;192 rr.ttl-=d_now.tv_sec; 193 193 ret.push_back(rr); 194 194 if(!(qtype==QType(QType::CNAME))) {// perhaps they really wanted a CNAME! … … 220 220 res=0; 221 221 map<string,NegCacheEntry>::const_iterator ni=s_negcache.find(toLower(qname)); 222 if(d_now < ni->second.ttd) {223 sttl=ni->second.ttd - d_now ;222 if(d_now.tv_sec < ni->second.ttd) { 223 sttl=ni->second.ttd - d_now.tv_sec; 224 224 LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl; 225 225 res=RCode::NXDomain; … … 242 242 map<string,NegCacheEntry>::const_iterator ni=s_negcache.find(tuple); 243 243 if(ni!=s_negcache.end()) { 244 if(d_now < ni->second.ttd) {245 sttl=ni->second.ttd - d_now ;244 if(d_now.tv_sec < ni->second.ttd) { 245 sttl=ni->second.ttd - d_now.tv_sec; 246 246 LOG<<prefix<<qname<<": "<<qtype.getName()<<" is negatively cached for another "<<sttl<<" seconds"<<endl; 247 247 res=RCode::NoError; // only this record doesn't exist … … 259 259 set<DNSResourceRecord> cset; 260 260 bool found=false, expired=false; 261 if(RC.get(d_now , sqname,sqt,&cset)>0) {261 if(RC.get(d_now.tv_sec, sqname,sqt,&cset)>0) { 262 262 LOG<<prefix<<qname<<": Found cache hit for "<<sqt.getName()<<": "; 263 263 for(set<DNSResourceRecord>::const_iterator j=cset.begin();j!=cset.end();++j) { 264 264 LOG<<j->content; 265 if(j->ttl>(unsigned int) d_now ) {265 if(j->ttl>(unsigned int) d_now.tv_sec) { 266 266 DNSResourceRecord rr=*j; 267 rr.ttl-=d_now ;267 rr.ttl-=d_now.tv_sec; 268 268 if(giveNegative) { 269 269 rr.d_place=DNSResourceRecord::AUTHORITY; … … 322 322 for(set<string>::const_iterator i=nameservers.begin();i!=nameservers.end();++i) { 323 323 rnameservers.push_back(*i); 324 speeds[*i]=nsSpeeds[toLower(*i)].get(); 324 DecayingEwma& temp=nsSpeeds[toLower(*i)]; 325 speeds[*i]=temp.get(&d_now); 325 326 } 326 327 random_shuffle(rnameservers.begin(),rnameservers.end()); … … 339 340 L<<endl; 340 341 } 341 342 342 return rnameservers; 343 343 } … … 378 378 bool doTCP=false; 379 379 380 if(s_throttle.shouldThrottle(d_now , remoteIP+"|"+qname+"|"+qtype.getName())) {380 if(s_throttle.shouldThrottle(d_now.tv_sec, remoteIP+"|"+qname+"|"+qtype.getName())) { 381 381 LOG<<prefix<<qname<<": query throttled "<<endl; 382 382 s_throttledqueries++; … … 403 403 LOG<<prefix<<qname<<": error resolving"<<endl; 404 404 405 nsSpeeds[toLower(*tns)].submit(1000000 ); // 1 sec405 nsSpeeds[toLower(*tns)].submit(1000000, &d_now); // 1 sec 406 406 407 s_throttle.throttle(d_now , remoteIP+"|"+qname+"|"+qtype.getName(),20,5);407 s_throttle.throttle(d_now.tv_sec, remoteIP+"|"+qname+"|"+qtype.getName(),20,5); 408 408 continue; 409 409 } 410 d_now=time(0);410 gettimeofday(&d_now, 0); 411 411 } 412 412 … … 425 425 if(d_lwr.d_rcode==RCode::ServFail) { 426 426 LOG<<prefix<<qname<<": "<<*tns<<" returned a ServFail, trying sibling NS"<<endl; 427 s_throttle.throttle(d_now ,remoteIP+"|"+qname+"|"+qtype.getName(),60,3);427 s_throttle.throttle(d_now.tv_sec,remoteIP+"|"+qname+"|"+qtype.getName(),60,3); 428 428 continue; 429 429 } … … 452 452 DNSResourceRecord rr=*i; 453 453 rr.d_place=DNSResourceRecord::ANSWER; 454 rr.ttl+=d_now ;454 rr.ttl+=d_now.tv_sec; 455 455 // rr.ttl=time(0)+10+10*rr.qtype.getCode(); 456 456 tcache[toLower(i->qname)+"|"+i->qtype.getName()].insert(rr); … … 489 489 NegCacheEntry ne; 490 490 ne.name=i->qname; 491 ne.ttd=d_now + i->ttl;491 ne.ttd=d_now.tv_sec + i->ttl; 492 492 s_negcache[toLower(qname)]=ne; 493 493 negindic=true; … … 528 528 NegCacheEntry ne; 529 529 ne.name=i->qname; 530 ne.ttd=d_now + i->ttl;530 ne.ttd=d_now.tv_sec + i->ttl; 531 531 s_negcache[toLower(qname)+"|"+qtype.getName()]=ne; 532 532 negindic=true; … … 560 560 else { 561 561 LOG<<prefix<<qname<<": status=NS "<<*tns<<" is lame for '"<<auth<<"', trying sibling NS"<<endl; 562 s_throttle.throttle(d_now , remoteIP+"|"+qname+"|"+qtype.getName(),60,0);562 s_throttle.throttle(d_now.tv_sec, remoteIP+"|"+qname+"|"+qtype.getName(),60,0); 563 563 } 564 564 } … … 607 607 DNSResourceRecord ns=*k; 608 608 ns.d_place=DNSResourceRecord::AUTHORITY; 609 ns.ttl-=d_now ;609 ns.ttl-=d_now.tv_sec; 610 610 ret.push_back(ns); 611 611 } -
trunk/pdns/pdns/syncres.hh
r466 r469 12 12 #include "misc.hh" 13 13 #include "lwres.hh" 14 14 #include <boost/utility.hpp> 15 15 16 16 /* external functions, opaque to us */ … … 88 88 { 89 89 public: 90 DecayingEwma() : d_last(getTime()) , d_lastget(time(0)), d_val(0.0) { 91 } 92 void submit(int val) 93 { 94 double now=getTime(); 90 DecayingEwma() : d_last(getTime()) , d_lastget(d_last), d_val(0.0) { 91 92 } 93 94 DecayingEwma(const DecayingEwma& orig) : d_last(orig.d_last), d_lastget(orig.d_lastget), d_val(orig.d_val) 95 { 96 97 } 98 99 void submit(int val, struct timeval*tv = 0) 100 { 101 double now; 102 if(tv) 103 now=tv->tv_sec + tv->tv_usec/1000000.0; 104 else 105 now=getTime(); 106 95 107 double diff=d_last-now; 96 108 d_last=now; … … 98 110 d_val=(1-factor)*val+ factor*d_val; 99 111 } 100 double get() 101 { 102 double now=getTime(); 112 113 double get(struct timeval*tv = 0) 114 { 115 double now; 116 if(tv) 117 now=tv->tv_sec + tv->tv_usec/1000000.0; 118 else 119 now=getTime(); 120 103 121 double diff=d_lastget-now; 104 122 d_lastget=now; … … 108 126 109 127 private: 110 128 DecayingEwma& operator=(const DecayingEwma&); 111 129 double d_last; 112 130 double d_lastget; … … 118 136 { 119 137 public: 120 SyncRes() : d_outqueries(0), d_tcpoutqueries(0), d_throttledqueries(0), d_timeouts(0), d_cacheonly(false), d_nocache(false) , d_now(time(0)) {}138 SyncRes() : d_outqueries(0), d_tcpoutqueries(0), d_throttledqueries(0), d_timeouts(0), d_cacheonly(false), d_nocache(false) { gettimeofday(&d_now, 0); } 121 139 int beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret); 122 140 void setId(int id) … … 172 190 bool d_nocache; 173 191 LWRes d_lwr; 174 time_td_now;192 struct timeval d_now; 175 193 176 194 struct GetBestNSAnswer