]> granicus.if.org Git - pdns/commitdiff
fix up the wrong size of the 'remotes' ringbuffer with pdns-distributes-queries,... rec-3.7.0-rc2
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 4 Feb 2015 08:55:13 +0000 (09:55 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 4 Feb 2015 08:57:06 +0000 (09:57 +0100)
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc

index 96251311a415dee66e827bc1e43acb37243afc84..86f556e90657cc9361d863a45162151d3f7208c4 100644 (file)
@@ -127,7 +127,7 @@ listenSocketsAddresses_t g_listenSocketsAddresses; // is shared across all threa
 
 __thread MT_t* MT; // the big MTasker
 
-unsigned int g_numThreads;
+unsigned int g_numThreads, g_numWorkerThreads;
 
 #define LOCAL_NETS "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10"
 // Bad Nets taken from both:
@@ -1296,9 +1296,9 @@ static void houseKeeping(void *)
       DTime dt;
       dt.setTimeval(now);
       t_RC->doPrune(); // this function is local to a thread, so fine anyhow
-      t_packetCache->doPruneTo(::arg().asNum("max-packetcache-entries") / g_numThreads);
+      t_packetCache->doPruneTo(::arg().asNum("max-packetcache-entries") / g_numWorkerThreads);
       
-      pruneCollection(t_sstorage->negcache, ::arg().asNum("max-cache-entries") / (g_numThreads * 10), 200);
+      pruneCollection(t_sstorage->negcache, ::arg().asNum("max-cache-entries") / (g_numWorkerThreads * 10), 200);
       
       if(!((cleanCounter++)%40)) {  // this is a full scan!
        time_t limit=now.tv_sec-300;
@@ -1785,20 +1785,19 @@ static void checkLinuxIPv6Limits()
 }
 static void checkOrFixFDS()
 {
-  unsigned int availFDs=getFilenumLimit();
-  if(g_maxMThreads * g_numThreads > availFDs) {
-    if(getFilenumLimit(true) >= g_maxMThreads * g_numThreads) {
-      setFilenumLimit(g_maxMThreads * g_numThreads);
-      L<<Logger::Warning<<"Raised soft limit on number of filedescriptors to "<<g_maxMThreads * g_numThreads<<" to match max-mthreads and threads settings"<<endl;
+  unsigned int availFDs=getFilenumLimit()-10; // some healthy margin, thanks AJ ;-)
+  if(g_maxMThreads * g_numWorkerThreads > availFDs) {
+    if(getFilenumLimit(true) >= g_maxMThreads * g_numWorkerThreads) {
+      setFilenumLimit(g_maxMThreads * g_numWorkerThreads);
+      L<<Logger::Warning<<"Raised soft limit on number of filedescriptors to "<<g_maxMThreads * g_numWorkerThreads<<" to match max-mthreads and threads settings"<<endl;
     }
     else {
-      int newval = getFilenumLimit(true) / g_numThreads;
-      L<<Logger::Warning<<"Insufficient number of filedescriptors available for max-mthreads*threads setting! ("<<availFDs<<" < "<<g_maxMThreads*g_numThreads<<"), reducing max-mthreads to "<<newval<<endl;
+      int newval = getFilenumLimit(true) / g_numWorkerThreads;
+      L<<Logger::Warning<<"Insufficient number of filedescriptors available for max-mthreads*threads setting! ("<<availFDs<<" < "<<g_maxMThreads*g_numWorkerThreads<<"), reducing max-mthreads to "<<newval<<endl;
       g_maxMThreads = newval;
-      setFilenumLimit(g_maxMThreads * g_numThreads);
+      setFilenumLimit(g_maxMThreads * g_numWorkerThreads);
     }
   }
-
 }
 
 void* recursorThread(void*);
@@ -2051,7 +2050,8 @@ int serviceMain(int argc, char*argv[])
   }
 
   Utility::dropUserPrivs(newuid);
-  
+  g_numThreads = ::arg().asNum("threads") + ::arg().mustDo("pdns-distributes-queries");
+  g_numWorkerThreads = ::arg().asNum("threads");
   makeThreadPipes();
   
   g_tcpTimeout=::arg().asNum("client-tcp-timeout");
@@ -2104,16 +2104,18 @@ try
   }
   
   t_traceRegex = new shared_ptr<Regex>();
-  unsigned int ringsize=::arg().asNum("stats-ringbuffer-entries") / g_numThreads;
+  unsigned int ringsize=::arg().asNum("stats-ringbuffer-entries") / g_numWorkerThreads;
   if(ringsize) {
     t_remotes = new addrringbuf_t();
-    t_remotes->set_capacity(ringsize);   
+    if(g_weDistributeQueries)  // if so, only 1 thread does recvfrom
+      t_remotes->set_capacity(::arg().asNum("stats-ringbuffer-entries"));   
+    else
+      t_remotes->set_capacity(ringsize);   
     t_servfailremotes = new addrringbuf_t();
     t_servfailremotes->set_capacity(ringsize);   
     t_largeanswerremotes = new addrringbuf_t();
     t_largeanswerremotes->set_capacity(ringsize);   
 
-
     t_queryring = new boost::circular_buffer<pair<string, uint16_t> >();
     t_queryring->set_capacity(ringsize);   
     t_servfailqueryring = new boost::circular_buffer<pair<string, uint16_t> >();
index 117c7a5ea780fe046650a3a2a6d5069b19ec5a29..aefce242de74c4abe5ec8c2435d70f98ec03d643 100644 (file)
@@ -587,8 +587,6 @@ static void doExit()
 
 static void doExitNicely()
 {
-  //extern void printCallers();
-  // printCallers();
   doExitGeneric(true);
 }
 
@@ -641,7 +639,7 @@ vector<ComboAddress>* pleaseGetServfailRemotes()
   vector<ComboAddress>* ret = new vector<ComboAddress>();
   if(!t_servfailremotes)
     return ret;
-  ret->reserve(t_remotes->size());
+  ret->reserve(t_servfailremotes->size());
   BOOST_FOREACH(const ComboAddress& ca, *t_servfailremotes) {
     ret->push_back(ca);
   }
@@ -653,7 +651,7 @@ vector<ComboAddress>* pleaseGetLargeAnswerRemotes()
   vector<ComboAddress>* ret = new vector<ComboAddress>();
   if(!t_largeanswerremotes)
     return ret;
-  ret->reserve(t_remotes->size());
+  ret->reserve(t_largeanswerremotes->size());
   BOOST_FOREACH(const ComboAddress& ca, *t_largeanswerremotes) {
     ret->push_back(ca);
   }