【发布时间】:2012-01-29 04:04:30
【问题描述】:
我对 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());
和 ServerBootstrap:
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)));
您对此配置有何建议?
【问题讨论】:
标签: java performance tcp netty tcplistener