From: Remi Gacogne Date: Thu, 21 Mar 2019 17:45:40 +0000 (+0100) Subject: dnsdist: Don't scan for TCP timeouts more than once every second X-Git-Tag: dnsdist-1.4.0-alpha1~25^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e90a5cb6d7926a1259d62b7d0e7a675556439165;p=thirdparty%2Fpdns.git dnsdist: Don't scan for TCP timeouts more than once every second --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 9889583e98..97ca4c73e0 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -1026,6 +1026,7 @@ void tcpClientThread(int pipefd) data.mplexer->addReadFD(pipefd, handleIncomingTCPQuery, &data); time_t lastTCPCleanup = time(nullptr); + time_t lastTimeoutScan = time(nullptr); struct timeval now; gettimeofday(&now, 0); @@ -1037,30 +1038,33 @@ void tcpClientThread(int pipefd) lastTCPCleanup = now.tv_sec; } - auto expiredReadConns = data.mplexer->getTimeouts(now, false); - for(const auto& conn : expiredReadConns) { - auto state = boost::any_cast>(conn.second); - if (conn.first == state->d_ci.fd) { - vinfolog("Timeout (read) from remote TCP client %s", state->d_ci.remote.toStringWithPort()); - } - else if (state->d_ds) { - vinfolog("Timeout (read) from remote backend %s", state->d_ds->getName()); + if (now.tv_sec > lastTimeoutScan) { + lastTimeoutScan = now.tv_sec; + auto expiredReadConns = data.mplexer->getTimeouts(now, false); + for(const auto& conn : expiredReadConns) { + auto state = boost::any_cast>(conn.second); + if (conn.first == state->d_ci.fd) { + vinfolog("Timeout (read) from remote TCP client %s", state->d_ci.remote.toStringWithPort()); + } + else if (state->d_ds) { + vinfolog("Timeout (read) from remote backend %s", state->d_ds->getName()); + } + data.mplexer->removeReadFD(conn.first); + state->d_lastIOState = IOState::Done; } - data.mplexer->removeReadFD(conn.first); - state->d_lastIOState = IOState::Done; - } - auto expiredWriteConns = data.mplexer->getTimeouts(now, true); - for(const auto& conn : expiredWriteConns) { - auto state = boost::any_cast>(conn.second); - if (conn.first == state->d_ci.fd) { - vinfolog("Timeout (write) from remote TCP client %s", state->d_ci.remote.toStringWithPort()); - } - else if (state->d_ds) { - vinfolog("Timeout (write) from remote backend %s", state->d_ds->getName()); + auto expiredWriteConns = data.mplexer->getTimeouts(now, true); + for(const auto& conn : expiredWriteConns) { + auto state = boost::any_cast>(conn.second); + if (conn.first == state->d_ci.fd) { + vinfolog("Timeout (write) from remote TCP client %s", state->d_ci.remote.toStringWithPort()); + } + else if (state->d_ds) { + vinfolog("Timeout (write) from remote backend %s", state->d_ds->getName()); + } + data.mplexer->removeWriteFD(conn.first); + state->d_lastIOState = IOState::Done; } - data.mplexer->removeWriteFD(conn.first); - state->d_lastIOState = IOState::Done; } } }