Skip to content

Commit

Permalink
Enable TCP NoDelay by default #1462
Browse files Browse the repository at this point in the history
Enabling NoDelay by default to avoid delayed TCP ACK's. Lettuce's flushing behavior is already optimized and the server is expected to respond without waiting for more data.
  • Loading branch information
mp911de committed Oct 16, 2020
1 parent d3d5054 commit deca4c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/main/java/io/lettuce/core/SocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SocketOptions {

public static final boolean DEFAULT_SO_KEEPALIVE = false;

public static final boolean DEFAULT_SO_NO_DELAY = false;
public static final boolean DEFAULT_SO_NO_DELAY = true;

private final Duration connectTimeout;

Expand Down Expand Up @@ -148,10 +148,13 @@ public Builder keepAlive(boolean keepAlive) {
}

/**
* Sets whether to disable Nagle's algorithm. Defaults to {@code false} (Nagle enabled). See
* Sets whether to disable/enable Nagle's algorithm. Defaults to {@code true} (Nagle disabled). See
* {@link #DEFAULT_SO_NO_DELAY}.
* <p>
* Disabling TCP NoDelay delays TCP {@code ACK} packets to await more data input before confirming the packet.
*
* @param tcpNoDelay {@code true} to disable Nagle's algorithm, {@code false} to enable Nagle's algorithm.
* @param tcpNoDelay {@code false} to disable TCP NoDelay (enable Nagle's algorithm), {@code true} to enable TCP NoDelay
* (disable Nagle's algorithm).
* @return {@code this}
* @see java.net.SocketOptions#TCP_NODELAY
*/
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/lettuce/core/SocketOptionsUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ void testNew() {
@Test
void testBuilder() {

SocketOptions sut = SocketOptions.builder().connectTimeout(1, TimeUnit.MINUTES).keepAlive(true).tcpNoDelay(true)
SocketOptions sut = SocketOptions.builder().connectTimeout(1, TimeUnit.MINUTES).keepAlive(true).tcpNoDelay(false)
.build();

assertThat(sut.isKeepAlive()).isTrue();
assertThat(sut.isTcpNoDelay()).isTrue();
assertThat(sut.isTcpNoDelay()).isFalse();
assertThat(sut.getConnectTimeout()).isEqualTo(Duration.ofMinutes(1));
}

Expand All @@ -67,7 +67,7 @@ void testCopy() {

void checkAssertions(SocketOptions sut) {
assertThat(sut.isKeepAlive()).isFalse();
assertThat(sut.isTcpNoDelay()).isFalse();
assertThat(sut.isTcpNoDelay()).isTrue();
assertThat(sut.getConnectTimeout()).isEqualTo(Duration.ofSeconds(10));
}
}

0 comments on commit deca4c7

Please sign in to comment.