__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:
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;
}
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*);
}
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");
}
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> >();
static void doExitNicely()
{
- //extern void printCallers();
- // printCallers();
doExitGeneric(true);
}
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);
}
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);
}