我创建了一个netty tcp客户端和服务器。我计算了客户端的总响应时间。当我进行负载测试时,我发现每8个请求需要很长时间。可能是什么原因?关于提高性能的任何指示。
Connecting to localhost:9065
PROCESSING TIME [32.508 ms]
PROCESSING TIME [1.952 ms]
PROCESSING TIME [2.157 ms]
PROCESSING TIME [2.818 ms]
PROCESSING TIME [1.788 ms]
PROCESSING TIME [368.311 ms]
PROCESSING TIME [3.107 ms]
PROCESSING TIME [1.856 ms]
PROCESSING TIME [1.973 ms]
PROCESSING TIME [2.14 ms]
PROCESSING TIME [2.022 ms]
PROCESSING TIME [1.781 ms]
PROCESSING TIME [1.967 ms]
PROCESSING TIME [411.338 ms]
PROCESSING TIME [3.252 ms]
PROCESSING TIME [1.769 ms]
PROCESSING TIME [1.746 ms]
PROCESSING TIME [4.04 ms]
PROCESSING TIME [1.758 ms]
PROCESSING TIME [1.81 ms]
PROCESSING TIME [1.817 ms]
PROCESSING TIME [1.686 ms]
PROCESSING TIME [317.336 ms]
PROCESSING TIME [3.084 ms]
PROCESSING TIME [3.624 ms]
PROCESSING TIME [3.147 ms]
PROCESSING TIME [1.95 ms]
PROCESSING TIME [2.16 ms]
PROCESSING TIME [1.987 ms]
PROCESSING TIME [1.9 ms]
PROCESSING TIME [335.572 ms]
PROCESSING TIME [1.835 ms]
PROCESSING TIME [1.707 ms]
PROCESSING TIME [1.896 ms]
PROCESSING TIME [3.084 ms]
我的客户端代码使用的是netty 5.0.0.Alpha2,我的服务器使用的是netty 4.0.30.Final,
我的客户端代码与
相同https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/echo/EchoClient.java https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/echo/EchoClientHandler.java
我的服务器代码是,
final EventLoopGroup parentGroup = new NioEventLoopGroup(5);
final EventLoopGroup childGroup = new NioEventLoopGroup();
try
{
final ServerBootstrap b = new ServerBootstrap();
b.group(parentGroup, childGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>()
{
@Override
public void initChannel(final SocketChannel ch) throws Exception
{
final ChannelPipeline p = ch.pipeline();
if (sslCtx != null)
{
p.addLast(sslCtx.newHandler(ch.alloc()));
}
NettyServer.this.framer = (Framer) Class.forName(NettyServer.this.manifest.getFramingConfig()).newInstance();
NettyServer.this.headerClass = Class.forName(NettyServer.this.manifest.getHeaderConfig());
final NettyServerHandler nettyServerHandler = new NettyServerHandler(NettyServer.this.moduleName, NettyServer.this.framer, NettyServer.this.headerClass,
NettyServer.this.requestProcessor.clone());
p.addLast(nettyServerHandler);
}
});
// Start the server.
final ChannelFuture f = b.bind(this.port).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
}
finally
{
// Shut down all event loops to terminate all threads.
parentGroup.shutdownGracefully();
childGroup.shutdownGracefully();
}