Permalink
Browse files

fix up the wrong size of the 'remotes' ringbuffer with pdns-distribut…

…es-queries, fix up finally the wrong sizing of caches in case of pdns-distributes-queries and slightly adjust the number of available filedescriptors based on reality. Thanks AJ ;-)
  • Loading branch information...
1 parent 0808712 commit f8f243b01215d6adcb59389f09ef494f1309041f @ahupowerdns ahupowerdns committed Feb 4, 2015
Showing with 20 additions and 20 deletions.
  1. +18 −16 pdns/pdns_recursor.cc
  2. +2 −4 pdns/rec_channel_rec.cc
View
@@ -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> >();
@@ -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);
}

0 comments on commit f8f243b

Please sign in to comment.