优化netty设置

This commit is contained in:
Guoqs
2024-11-28 10:09:51 +08:00
parent 4dee8da177
commit 2ca952740c

View File

@@ -50,9 +50,13 @@ public class NettyServerManager implements CommandLineRunner {
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.DEBUG))
// .option(ChannelOption.SO_BACKLOG, 128) // 默认128
.option(ChannelOption.SO_BACKLOG, 10240)
.option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.SO_BACKLOG, 1024)
// .option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true) // 保持连接
.childOption(ChannelOption.TCP_NODELAY, true) // 禁用 Nagle 算法
.childOption(ChannelOption.SO_RCVBUF, 64 * 1024) // 接收缓冲区
.childOption(ChannelOption.SO_SNDBUF, 64 * 1024) // 发送缓冲区
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(32 * 1024, 64 * 1024)) // 写缓冲水位
.childOption(ChannelOption.SO_REUSEADDR, true)
.childHandler(nettyServerChannelInitializer)
.localAddress(new InetSocketAddress(host, port));