From e41f8165b1ba1547f39aa6ee8bf2fb50956f2590 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 4 Dec 2015 16:01:40 +0100 Subject: [PATCH] Allow setting maxOustanding and maxTCPClientThreads in configuration This commit adds the setMaxTCPClientThreads() and setMaxUDPOutstanding() directives. These controls, respectively, the maximum number of TCP threads handling client connections and the maximum number of oustanding UDP queries to a given backend server. setMaxUDPOutstanding() is only usable at configuration-time, and not at runtime. --- pdns/README-dnsdist.md | 5 +++++ pdns/dnsdist-lua.cc | 10 ++++++++++ pdns/dnsdist.cc | 10 ++++++++-- pdns/dnsdist.hh | 3 +++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 0bf1b8b52..b5366c397 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -671,6 +671,11 @@ instantiate a server with additional parameters * newSuffixMatchNode(): returns a new SuffixMatchNode * member `check(DNSName)`: returns true if DNSName is matched by this group * member `add(DNSName)`: add this DNSName to the node + * Tuning related: + * setTCPRecvTimeout(n): set the read timeout on TCP connections from the client, in seconds. + * setTCPSendTimeout(n): set the write timeout on TCP connections from the client, in seconds. + * setMaxTCPClientThreads(n): set the maximum of TCP client threads, handling TCP connections. + * setMaxUDPOutstanding(n): set the maximum number of outstanding UDP queries to a given backend server. This can only be set at configuration time. All hooks --------- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 0b9931342..edc1ea216 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -897,6 +897,16 @@ vector> setupLua(bool client, const std::string& confi g_lua.writeFunction("setTCPSendTimeout", [](int timeout) { g_tcpSendTimeout=timeout; }); + g_lua.writeFunction("setMaxUDPOutstanding", [](uint16_t max) { + if (!g_configurationDone) { + g_maxOutstanding = max; + } else { + g_outputBuffer="Max UDP outstanding cannot be altered at runtime!\n"; + } + }); + + g_lua.writeFunction("setMaxTCPClientThreads", [](uint64_t max) { g_maxTCPClientThreads = max; }); + g_lua.writeFunction("dumpStats", [] { vector leftcolumn, rightcolumn; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index e19035d63..4dd205a59 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -654,6 +654,8 @@ catch(...) return false; } +std::atomic g_maxTCPClientThreads{10}; + void* maintThread() { int interval = 1; @@ -661,7 +663,7 @@ void* maintThread() for(;;) { sleep(interval); - if(g_tcpclientthreads.d_queued > 1 && g_tcpclientthreads.d_numthreads < 10) + if(g_tcpclientthreads.d_queued > 1 && g_tcpclientthreads.d_numthreads < g_maxTCPClientThreads) g_tcpclientthreads.addTCPClientThread(); for(auto& dss : g_dstates.getCopy()) { // this points to the actual shared_ptrs! @@ -1053,7 +1055,8 @@ char* my_generator(const char* text, int state) vector words{"showRules()", "shutdown()", "rmRule(", "mvRule(", "addACL(", "addLocal(", "setServerPolicy(", "setServerPolicyLua(", "newServer(", "rmServer(", "showServers()", "show(", "newDNSName(", "newSuffixMatchNode(", "controlSocket(", "topClients(", "showResponseLatency()", "newQPSLimiter(", "makeKey()", "setKey(", "testCrypto()", "addAnyTCRule()", "showServerPolicy()", "setACL(", "showACL()", "addDomainBlock(", - "addPoolRule(", "addQPSLimit(", "topResponses(", "topQueries(", "topRule()", "setDNSSECPool(", "addDelay("}; + "addPoolRule(", "addQPSLimit(", "topResponses(", "topQueries(", "topRule()", "setDNSSECPool(", "addDelay(", + "setMaxUDPOutstanding(", "setMaxTCPClientThreads("}; static int s_counter=0; int counter=0; if(!state) @@ -1096,6 +1099,7 @@ struct string gid; } g_cmdLine; +std::atomic g_configurationDone{false}; int main(int argc, char** argv) try @@ -1244,6 +1248,8 @@ try g_locals.push_back({ComboAddress("127.0.0.1", 53), true}); + g_configurationDone = true; + vector toLaunch; for(const auto& local : g_locals) { ClientState* cs = new ClientState; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 54e56e64f..537d34ed6 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -361,6 +361,9 @@ extern std::string g_key; // in theory needs locking extern bool g_truncateTC; extern int g_tcpRecvTimeout; extern int g_tcpSendTimeout; +extern uint16_t g_maxOutstanding; +extern std::atomic g_configurationDone; +extern std::atomic g_maxTCPClientThreads; struct dnsheader; void controlThread(int fd, ComboAddress local); -- 2.40.0