From: Bert Hubert Date: Thu, 14 Jul 2005 20:45:57 +0000 (+0000) Subject: made dnsreplay lots more efficient X-Git-Tag: pdns-2.9.18~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e921494a24e99efc8576f4ab00701ef89351f291;p=thirdparty%2Fpdns.git made dnsreplay lots more efficient git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@446 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index 189ed690da..74d8e94b3e 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -35,6 +35,7 @@ using namespace boost; using namespace std; StatBag S; +bool s_quiet=true; class DNSIDManager { @@ -42,10 +43,10 @@ public: int getID() { - - for(unsigned int n=0; n < d_freeids.size() ; ++n) + for(uint16_t n=d_lastfreeid+1; n != d_lastfreeid ; ++n) if(!d_freeids[n]) { d_freeids[n]=1; + d_lastfreeid=n; return n; } cerr<<"Out of free IDs"<(id)); d_freeids[id]=0; + d_lastfreeid=id-1; } private: bitset<65536> d_freeids; + uint16_t d_lastfreeid; } s_idmanager; struct QuestionData @@ -81,15 +84,15 @@ unsigned int s_questions, s_answers, s_timedout, s_perfect, s_mostly, s_noorigin unsigned int s_webetter, s_origbetter, s_norecursionavailable; unsigned int s_weunmatched, s_origunmatched; unsigned int s_wednserrors, s_origdnserrors; -// XXX FIXME wasteful + void pruneQids() { - qids_t nqids; struct timeval now; gettimeofday(&now, 0); - for(qids_t::iterator i=qids.begin(); i!=qids.end(); ++i) + + for(qids_t::iterator i=qids.begin(); i!=qids.end(); ) { if(now.tv_sec < i->second.d_sentTime.tv_sec + 4 || (now.tv_sec == i->second.d_sentTime.tv_sec && now.tv_usec < i->second.d_sentTime.tv_usec)) - nqids[i->first]=i->second; + ++i; else { s_idmanager.releaseID(i->second.d_assignedID); if(i->second.d_newRcode==-1) @@ -98,9 +101,9 @@ void pruneQids() s_nooriginalanswer++; else cerr<<"Impossible - finished QI in the pool"<& compacted) @@ -120,45 +123,56 @@ set > s_origbetterset; void measureResultAndClean(const QuestionIdentifier& qi) { QuestionData qd=qids[qi]; - cout< canonicOrig, canonicNew; compactAnswerSet(qd.d_origAnswers, canonicOrig); compactAnswerSet(qd.d_newAnswers, canonicNew); - - cout<<", "<::const_iterator i=canonicOrig.begin(); i!=canonicOrig.end(); ++i) + if(!s_quiet) { + cout<<"orig:\n"; + for(set::const_iterator i=canonicOrig.begin(); i!=canonicOrig.end(); ++i) + cout<<"\t"<d_label<<"\t"<d_type)<<"\t'" << (i->d_content ? i->d_content->getZoneRepresentation() : "") <<"'\n"; + cout<<"new:\n"; + for(set::const_iterator i=canonicNew.begin(); i!=canonicNew.end(); ++i) cout<<"\t"<d_label<<"\t"<d_type)<<"\t'" << (i->d_content ? i->d_content->getZoneRepresentation() : "") <<"'\n"; - cout<<"new:\n"; - for(set::const_iterator i=canonicNew.begin(); i!=canonicNew.end(); ++i) - cout<<"\t"<d_label<<"\t"<d_type)<<"\t'" << (i->d_content ? i->d_content->getZoneRepresentation() : "") <<"'\n"; - cout<<"\n"; + cout<<"\n"; + } } qids.erase(qi); @@ -250,7 +264,16 @@ try if(!((once++)%2000)) { Lock l(&s_lock); + + if(qids.size() > 1000) { + cerr<<"Too many questions outstanding, waiting a second"<sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); @@ -332,7 +364,8 @@ try } else { s_origunmatched++; - cout<<"Unmatched original answer "<