]> granicus.if.org Git - pdns/commitdiff
remove global distributor and replace by 1 distributor per receiver thread, thanks...
authorBert Hubert <bert.hubert@netherlabs.nl>
Wed, 3 Oct 2012 13:53:21 +0000 (13:53 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Wed, 3 Oct 2012 13:53:21 +0000 (13:53 +0000)
see http://wiki.powerdns.com/trac/ticket/583 for details

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2731 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/common_startup.cc
pdns/distributor.hh

index baedec5905ed6e0eb939d6a411c8b4e7cc37956d..bb289f1cc1edd4244f16ba3dfd6c1b00584dfa8d 100644 (file)
@@ -212,15 +212,11 @@ void sendout(const DNSDistributor::AnswerData &AD)
   delete AD.A;  
 }
 
-static DNSDistributor* g_distributor;
-static pthread_mutex_t d_distributorlock =PTHREAD_MUTEX_INITIALIZER;
-static bool g_mustlockdistributor;
-
 //! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for further processing
 void *qthread(void *number)
 {
   DNSPacket *P;
-
+  DNSDistributor *distributor = new DNSDistributor(::arg().asNum("distributor-threads")); // the big dispatcher!
   DNSPacket question;
   DNSPacket cached;
 
@@ -240,7 +236,7 @@ void *qthread(void *number)
       if(!((numreceived++)%250)) { // maintenance tasks
         S.set("latency",(int)avg_latency);
         int qcount, acount;
-        g_distributor->getQueueSizes(qcount, acount);
+        distributor->getQueueSizes(qcount, acount);
         S.set("qsize-q",qcount);
       }
     }
@@ -291,7 +287,7 @@ void *qthread(void *number)
       continue;
     }
     
-    if(g_distributor->isOverloaded()) {
+    if(distributor->isOverloaded()) {
       if(logDNSQueries) 
         L<<"Dropped query, db is overloaded"<<endl;
       continue;
@@ -300,12 +296,7 @@ void *qthread(void *number)
     if(logDNSQueries) 
       L<<"packetcache MISS"<<endl;
 
-    if(g_mustlockdistributor) {
-      Lock l(&d_distributorlock);
-      g_distributor->question(P, &sendout); // otherwise, give to the distributor
-    }
-    else
-      g_distributor->question(P, &sendout); // otherwise, give to the distributor
+    distributor->question(P, &sendout); // otherwise, give to the distributor
   }
   return 0;
 }
@@ -361,10 +352,6 @@ void mainthread()
     TN->go(); // tcp nameserver launch
     
   //  fork(); (this worked :-))
-  g_distributor = new DNSDistributor(::arg().asNum("distributor-threads")); // the big dispatcher!
-  if(::arg().asNum("receiver-threads") > 1) {
-    g_mustlockdistributor=true;
-  }
   unsigned int max_rthreads= ::arg().asNum("receiver-threads");
   for(unsigned int n=0; n < max_rthreads; ++n)
     pthread_create(&qtid,0,qthread, reinterpret_cast<void *>(n)); // receives packets
index bdca89bb627d55cc7c4ebcde2317585e2257a1cf..38784e0d5c5d3f1ee077343d6cbcc984f5081520 100644 (file)
@@ -171,15 +171,16 @@ template<class Answer, class Question, class Backend>void *Distributor<Answer,Qu
 
       QuestionData QD=us->questions.front();
 
+      us->questions.pop();
+      pthread_mutex_unlock(&us->q_lock);
+
       Question *q=QD.Q;
       
-      us->questions.pop();
 
       if(us->d_overloaded && qcount <= overloadQueueLength/10) {
         us->d_overloaded=false;
       }
       
-      pthread_mutex_unlock(&us->q_lock);
       Answer *a;      
 
 #ifndef SMTPREDIR
@@ -297,11 +298,12 @@ template<class Answer, class Question, class Backend>int Distributor<Answer,Ques
     pthread_create(&tid,0,&makeThread,static_cast<void *>(this));
   }
 
-  pthread_mutex_lock(&q_lock);
   QuestionData QD;
   QD.Q=q;
   QD.id=nextid++;
   QD.callback=callback;
+
+  pthread_mutex_lock(&q_lock);
   questions.push(QD);
   pthread_mutex_unlock(&q_lock);