套接字接受Netty的延迟

时间:2016-12-08 12:59:35

标签: netty

有时客户端必须在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解决了我的问题!

1 个答案:

答案 0 :(得分:0)

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