]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Set TCP_NODELAY on the TCP connection to backends 11734/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 30 Jun 2022 09:06:24 +0000 (11:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 30 Jun 2022 09:06:24 +0000 (11:06 +0200)
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.

pdns/dnsdistdist/dnsdist-tcp-downstream.cc

index 418bf6b5f0e296fcd6587b69ba6e7be953c7728f..72809fbbe7fd03d6881183d473fe730045aa2b0e 100644 (file)
@@ -76,6 +76,12 @@ bool ConnectionToBackend::reconnect()
       auto socket = std::make_unique<Socket>(d_ds->d_config.remote.sin4.sin_family, SOCK_STREAM, 0);
       DEBUGLOG("result of socket() is "<<socket->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());