我有一些关于 Netty(服务器端)、TCP/IP 应用程序的问题;
我想知道在将请求从老板线程传递到工作线程时是否会因为 netty(由于缺少配置等)而出现延迟?
我在用 :
new OrderedMemoryAwareThreadPoolExecutor(350, 0, 0, 1, TimeUnit.SECONDS);
实际上,我设置了最大线程数350
因为我不确定最佳数量。我每分钟记录一次同时工作线程数,似乎平均值太低(勉强超过10
)。所以我会减少这个数字,因为它不是必需的。
为了获得最佳性能,是否还有其他参数、我应该注意的要点?
bootstrap.setOption("tcpNoDelay", true);
- 设置这个参数有什么缺点吗?考虑到交货时间非常重要。
线程池执行器:
OrderedMemoryAwareThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(48, 0, 0, 1, TimeUnit.SECONDS);
这是我的管道工厂:
ChannelPipeline pipeline = pipeline();
pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(GProperties.getIntProperty("decoder.maxFrameLength", 8000 * 1024), Delimiters.nulDelimiter()));
pipeline.addLast("stringDecoder", new StringDecoder( CharsetUtil.UTF_8 ));
pipeline.addLast("frameEncoder", new NullTermMessageEncoder());
pipeline.addLast("stringEncoder", new JSONEncoder( CharsetUtil.UTF_8 ));
pipeline.addLast("timeout", new IdleStateHandler(idleTimer, 42 , 0, 0));
pipeline.addLast("executor", new ExecutionHandler(executor));
pipeline.addLast("handler", new GServerHandler());
和服务器引导程序:
gServerBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
gServerBootstrap.setPipelineFactory(new GServerPipelineFactory());
gServerBootstrap.setOption("backlog", 8129);
gServerBootstrap.setOption("child.tcpNoDelay", true);
gServerBootstrap.bind(new InetSocketAddress(GProperties.getIntProperty("server.port", 7679)));
您对此配置有何建议?