【问题标题】:Netty Latency issueNetty 延迟问题
【发布时间】:2014-06-30 16:50:53
【问题描述】:

我是新用户网。我正在使用 netty 4.0.19-Final 版本。我正在使用 50 个客户端对 EchoServer 示例进行负载测试。下面是我的配置。我总是得到大约 300 毫秒的延迟。我正在尝试将延迟减少到 100 微秒左右。有什么我可以尝试达到预期的性能吗?我所有的客户端都是持久客户端,并且会延迟 10 毫秒发送消息。

        ServerBootstrap b = new ServerBootstrap();
        b.group(workerGroup)
                .channel(NioServerSocketChannel.class)
                .localAddress(NetUtil.LOCALHOST, Integer.valueOf(8080))
                .option(ChannelOption.SO_BACKLOG, 128)
                .childOption(ChannelOption.SO_KEEPALIVE, true)


                .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .childOption(ChannelOption.SO_SNDBUF, 1045678)
                .childOption(ChannelOption.SO_RCVBUF, 1045678)
                .option(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.TCP_NODELAY, true)
                 // .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    public void initChannel(SocketChannel ch)
                            throws Exception {
                        ch.pipeline()
                        //.addLast(new LoggingHandler(LogLevel.INFO))
                                .addLast(new EchoServerHandler());
                    }
                });

        // Start the server.
        ChannelFuture f = b.bind(PORT).sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();

           EchoServerHandler:
  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) {
      ctx.write(msg);

  }

  @Override
  public void channelReadComplete(ChannelHandlerContext ctx) {
      ctx.flush();
  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
      // Close the connection when an exception is raised.
      cause.printStackTrace();
      ctx.close();
  }

【问题讨论】:

    标签: performance netty


    【解决方案1】:

    尝试调用 ctx.writeAndFlush(...) 您可能还需要调整缓冲区大小等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多