Skip to content

Commit 160b490

Browse files
authored
Merge pull request #184 from fanson/perf/tcp-tuning
perf: add TCP_NODELAY, SO_BACKLOG, SO_REUSEADDR for low-latency RESP
2 parents 472d8a8 + b17ecde commit 160b490

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/github/tonivade/resp/RespServer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class RespServer implements Resp {
5353

5454
private static final int BUFFER_SIZE = 1024 * 1024;
5555
private static final int MAX_FRAME_SIZE = BUFFER_SIZE * 100;
56+
private static final int DEFAULT_BACKLOG = 1024;
5657

5758
private static final String DEFAULT_HOST = "localhost";
5859
private static final int DEFAULT_PORT = 12345;
@@ -79,10 +80,13 @@ public void start() {
7980
bootstrap.group(bossGroup, workerGroup)
8081
.channel(NioServerSocketChannel.class)
8182
.childHandler(new RespInitializerHandler(this))
83+
.option(ChannelOption.SO_BACKLOG, DEFAULT_BACKLOG)
84+
.option(ChannelOption.SO_REUSEADDR, true)
8285
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
8386
.childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE)
8487
.childOption(ChannelOption.SO_SNDBUF, BUFFER_SIZE)
8588
.childOption(ChannelOption.SO_KEEPALIVE, true)
89+
.childOption(ChannelOption.TCP_NODELAY, true)
8690
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
8791

8892
future = bootstrap.bind(serverContext.getHost(), serverContext.getPort());

0 commit comments

Comments
 (0)