【发布时间】:2017-04-23 17:38:57
【问题描述】:
有时客户端必须在 Netty 服务器建立套接字连接之前发送大量 SYN 数据包。例如看一些用tcpdump制作的数据包
12:23:30.166272 IP (tos 0x0, ttl 53, id 61857, offset 0, flags [DF], proto TCP (6), length 60)
SOURCE.25809 > DEST.7780: Flags [S], cksum 0x4bf4 (correct), seq 3364886260, win 5200, options [mss 1380,nop,wscale 0,nop,nop,TS val 264 ecr 0], length 0
12:23:54.067379 IP (tos 0x0, ttl 53, id 61858, offset 0, flags [DF], proto TCP (6), length 60)
SOURCE.53156 > DEST.7780: Flags [S], cksum 0x2b21 (correct), seq 2559114443, win 5200, options [mss 1380,nop,wscale 0,nop,nop,TS val 312 ecr 0], length 0
12:24:30.027630 IP (tos 0x0, ttl 53, id 61859, offset 0, flags [DF], proto TCP (6), length 60)
SOURCE.40667 > DEST.7780: Flags [S], cksum 0x0feb (correct), seq 3417642326, win 5200, options [mss 1380,nop,wscale 0,nop,nop,TS val 384 ecr 0], length 0
下面是Netty服务器启动的相关代码:
static final DefaultEventExecutorGroup e1 = new DefaultEventExecutorGroup(3);
static final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
static final EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.childHandler(new SocketChannelInitializer(cpds, e1, redispool))
.childOption(ChannelOption.TCP_NODELAY, false)
.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS,2000)
.childOption(ChannelOption.SO_REUSEADDR, true);
ChannelFuture future = b.bind(address);
future.syncUninterruptibly();
channel = future.channel();
logger.info("Binded server to port: " + System.getProperty("port"));
return future;
希望有人能给我一个提示。
更新:
发现是linux内核的TCP问题,net.ipv4.tcp_tw_recycle = 0解决了我的问题!
【问题讨论】:
-
你应该回答你自己的问题并接受它。
标签: netty