diff --git a/src/common/io/socket/common.c b/src/common/io/socket/common.c index 47579db07..ee563adf6 100644 --- a/src/common/io/socket/common.c +++ b/src/common/io/socket/common.c @@ -63,6 +63,15 @@ sckOptionSet(int fd) ASSERT(socketLocal.init); + // Disable the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small + // amount of data. Our internal buffering minimizes the benefit of this optimization so lower latency is preferred. +#ifdef TCP_NODELAY + int socketValue = 1; + + THROW_ON_SYS_ERROR( + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &socketValue, sizeof(int)) == -1, ProtocolError, "unable set TCP_NODELAY"); +#endif + // Enable TCP keepalives if (socketLocal.keepAlive) { diff --git a/test/src/module/common/ioTlsTest.c b/test/src/module/common/ioTlsTest.c index 8aa501b08..534bfc2ae 100644 --- a/test/src/module/common/ioTlsTest.c +++ b/test/src/module/common/ioTlsTest.c @@ -125,12 +125,20 @@ testRun(void) THROW_ON_SYS_ERROR(fd == -1, HostConnectError, "unable to create socket"); // --------------------------------------------------------------------------------------------------------------------- - TEST_TITLE("enable keep-alive and options"); + TEST_TITLE("enable options"); sckInit(true, 32, 3113, 818); sckOptionSet(fd); socklen_t socketValueSize = sizeof(int); + int noDelayValue = 0; + + THROW_ON_SYS_ERROR( + getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &noDelayValue, &socketValueSize) == -1, ProtocolError, + "unable get TCP_NO_DELAY"); + + TEST_RESULT_INT(noDelayValue, 1, "check TCP_NODELAY"); + int keepAliveValue = 0; THROW_ON_SYS_ERROR(