我是新用户网络。我使用的是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();
}
答案 0 :(得分:0)
尝试调用ctx.writeAndFlush(...)此外,您可能需要调整缓冲区大小等。