From: Remi Gacogne Date: Thu, 19 Apr 2018 15:03:54 +0000 (+0200) Subject: rec: Add a new max-udp-queries-per-round setting X-Git-Tag: rec-4.1.4^2~6^2~1 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fpdns.git;a=commitdiff_plain;h=0d7833217b7189750aa1d720060aac5a1bbb4672 rec: Add a new max-udp-queries-per-round setting This new setting limits the number of UDP queries we attempt to handle after being woken up by the multiplexer and before returning back to process other events. Before this, we could end up trying to process queries after queries and almost never return from handleNewUDPQuestion() to process new events, meaning we could eventually end up never scheduling new mthreads or handle responses from authoritative servers for a long time, only sending responses for packetcache hits and creating new mthreads. (cherry picked from commit a5886e6adad3c19e3490fba1dc7e580defb83eee) --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index f8f3a948b2..97580d5838 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -145,6 +145,7 @@ static AtomicCounter counter; static std::shared_ptr g_initialDomainMap; // new threads needs this to be setup static std::shared_ptr g_initialAllowFrom; // new thread needs to be setup with this static size_t g_tcpMaxQueriesPerConn; +static size_t s_maxUDPQueriesPerRound; static uint64_t g_latencyStatSize; static uint32_t g_disthashseed; static unsigned int g_maxTCPPerClient; @@ -1835,7 +1836,7 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) fromaddr.sin6.sin6_family=AF_INET6; // this makes sure fromaddr is big enough fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), data, sizeof(data), &fromaddr); - for(;;) + for(size_t counter = 0; counter < s_maxUDPQueriesPerRound; counter++) if((len=recvmsg(fd, &msgh, 0)) >= 0) { firstQuery = false; @@ -3174,6 +3175,7 @@ static int serviceMain(int argc, char*argv[]) g_tcpTimeout=::arg().asNum("client-tcp-timeout"); g_maxTCPPerClient=::arg().asNum("max-tcp-per-client"); g_tcpMaxQueriesPerConn=::arg().asNum("max-tcp-queries-per-connection"); + s_maxUDPQueriesPerRound=::arg().asNum("max-udp-queries-per-round"); if (::arg().mustDo("snmp-agent")) { g_snmpAgent = std::make_shared("recursor", ::arg()["snmp-master-socket"]); @@ -3487,6 +3489,7 @@ int main(int argc, char **argv) ::arg().set("max-qperq", "Maximum outgoing queries per query")="50"; ::arg().set("max-total-msec", "Maximum total wall-clock time per query in milliseconds, 0 for unlimited")="7000"; ::arg().set("max-recursion-depth", "Maximum number of internal recursion calls per query, 0 for unlimited")="40"; + ::arg().set("max-udp-queries-per-round", "Maximum number of UDP queries processed per round, before returning back to normal processing")="10000"; ::arg().set("include-dir","Include *.conf files from this directory")=""; ::arg().set("security-poll-suffix","Domain name from which to query security update notifications")="secpoll.powerdns.com."; diff --git a/pdns/recursordist/docs/settings.rst b/pdns/recursordist/docs/settings.rst index 8940d8eb65..fcf80968ec 100644 --- a/pdns/recursordist/docs/settings.rst +++ b/pdns/recursordist/docs/settings.rst @@ -750,6 +750,18 @@ Maximum number of DNS queries in a TCP connection. Total maximum number of milliseconds of wallclock time the server may use to answer a single query. +.. _setting-max-udp-queries-per-round: + +``max-udp-queries-per-round`` +---------------------------------- +.. versionadded:: 4.2.0 + +- Integer +- Default: 10000 + +Maximum number of DNS queries processed in a single round after being woken up by the multiplexer, before +returning back to normal processing to handle other events. + .. _setting-minimum-ttl-override: ``minimum-ttl-override``