From: Remi Gacogne Date: Thu, 30 Jun 2022 09:06:24 +0000 (+0200) Subject: dnsdist: Set TCP_NODELAY on the TCP connection to backends X-Git-Tag: auth-4.8.0-alpha0~23^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=059c8f524ee1e467c06787d591b779e08a279439;p=thirdparty%2Fpdns.git dnsdist: Set TCP_NODELAY on the TCP connection to backends Setting `TCP_NODELAY` disables Nagle's algorithm, which is unfortunately not always playing nice with TCP delayed ACKs. This is especially true when the backend supports out-of-order processing, allowing dnsdist to send several queries at once without waiting for an answer. In that case dnsdist often has to wait several milliseconds (20ms is common) before the remote end decides to send the delayed ACK which allows us to send the next query. --- diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 418bf6b5f0..72809fbbe7 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -76,6 +76,12 @@ bool ConnectionToBackend::reconnect() auto socket = std::make_unique(d_ds->d_config.remote.sin4.sin_family, SOCK_STREAM, 0); DEBUGLOG("result of socket() is "<getHandle()); + /* disable NAGLE, which does not play nicely with delayed ACKs. + In theory we could be wasting up to 500 milliseconds waiting for + the other end to acknowledge our initial packet before we could + send the rest. */ + setTCPNoDelay(socket->getHandle()); + #ifdef SO_BINDTODEVICE if (!d_ds->d_config.sourceItfName.empty()) { int res = setsockopt(socket->getHandle(), SOL_SOCKET, SO_BINDTODEVICE, d_ds->d_config.sourceItfName.c_str(), d_ds->d_config.sourceItfName.length());