2016-12-08 76 views
0

在Netty服务器建立套接字连接之前,客户端有时需要发送大量SYN数据包。作为例子看到做了一些数据包与tcpdumpNetty中的套接字接受延迟

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解决了我的问题!

+0

你应该回答你自己的问题并接受它。 – nllsdfx

回答

0

我发现这是linux内核的TCP问题,net.ipv4.tcp_tw_recycle = 0解决了我的问题!