From ab8eb008c574f24e8df107d666c3d78e19de5297 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 18 Nov 2022 16:56:16 +0100 Subject: [PATCH] dnsdist: Reduce useless wake-ups from the event loop The TCP acceptor, UDP client and Lua network threads never needs to break out of the event loop. The outgoing DoH one only needs to do that once per second to check for timeouts. --- pdns/dnsdist-tcp.cc | 2 +- pdns/dnsdist.cc | 2 +- pdns/dnsdistdist/dnsdist-backend.cc | 4 ++++ pdns/dnsdistdist/dnsdist-lua-network.cc | 2 +- pdns/dnsdistdist/dnsdist-nghttp2.cc | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index c9f4120b77..13d6352f93 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -1526,7 +1526,7 @@ void tcpAcceptorThread(std::vector states) struct timeval tv; while (true) { - mplexer->run(&tv); + mplexer->run(&tv, -1); } } } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index d0b3fbec93..6cd5b86af5 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1818,7 +1818,7 @@ static void udpClientThread(std::vector states) struct timeval tv; while (true) { - mplexer->run(&tv); + mplexer->run(&tv, -1); } } } diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index 562cb8abe8..f38dc505b7 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -377,6 +377,10 @@ void DownstreamState::reportTimeoutOrError() void DownstreamState::handleUDPTimeouts() { + if (getProtocol() != dnsdist::Protocol::DoUDP) { + return; + } + if (s_randomizeIDs) { auto map = d_idStatesMap.lock(); for (auto it = map->begin(); it != map->end(); ) { diff --git a/pdns/dnsdistdist/dnsdist-lua-network.cc b/pdns/dnsdistdist/dnsdist-lua-network.cc index 4165025c66..819137a400 100644 --- a/pdns/dnsdistdist/dnsdist-lua-network.cc +++ b/pdns/dnsdistdist/dnsdist-lua-network.cc @@ -134,7 +134,7 @@ void NetworkListener::mainThread() struct timeval now; while (true) { - runOnce(now, 5000); + runOnce(now, -1); } } diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index 361fc087c5..c57a361fce 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -909,7 +909,7 @@ static void dohClientThread(int crossProtocolPipeFD) time_t lastTimeoutScan = now.tv_sec; for (;;) { - data.mplexer->run(&now); + data.mplexer->run(&now, 1000); if (now.tv_sec > lastTimeoutScan) { lastTimeoutScan = now.tv_sec; -- 2.47.2