背景下寻求建议:Netty的3.6.3.Final,爪哇1.7,斯卡拉2.9.x上分享Netty的老板/工人池
为了尽量减少线程(可能空转的)的数量,我想共享带有不同NIO套接字通道工厂(TCP)和一个NioDatagramChannelFactory的NIO客户端/服务器和工作者池。我至少使用两个(或Finagle堆栈中的三个)服务器/客户机引导程序集,每个引导程序都有自己的NIO套接字通道工厂。为每个boss和worker池使用新的缓存线程池会导致大部分时间未使用的线程负载。粗略的目标是将所有自举/通道工厂的工作人员数量限制为2 * CPU核心数量和CPU核心数量的老板数量。
我试图切换到NioServer/ClientBossPool和NioWorkerPool作为我自己的一套bootstraps。但根据底层ThreadPoolExecutor的配置,关闭引导会导致主线程在AbstractNioSelector关闭锁存器上永远等待。
class NioClientBossPoolTest {
@Test def shutdown() {
val corePoolSize = 1
val maxPoolSize = Integer.MAX_VALUE
val keepAliveSeconds = 60
val keepAliveUnit = TimeUnit.SECONDS
val blocking = true
val queue: BlockingQueue[Runnable] =
if(blocking) new LinkedBlockingQueue[Runnable](Integer.MAX_VALUE)
else new SynchronousQueue[Runnable]()
val executor = new ThreadPoolExecutor(corePoolSize,
maxPoolSize,
keepAliveSeconds,
keepAliveUnit,
queue)
val clientBossPool = new NioClientBossPool(executor, 1) // B
new NioServerBossPool(executor, 1) // C
val workerPool = new NioWorkerPool(executor, 1) // A
val channelFactory = new NioClientSocketChannelFactory(clientBossPool, workerPool)
val bootstrap = new ClientBootstrap(channelFactory)
// hangs waiting for shutdown latch in AbstractNioSelector (NioWorker or NioClientBoss
// depending on the order of statement A, B, C) for
// LinkedBlockingQueue, corePoolSize = 1 and sequence of statements A, B and C other than [B, A, C]
// LinkedBlockingQueue, corePoolSize = 2 and sequence of statements A, B and C other than
// [A, B, C], [B, C, A] and [C, B, A]
bootstrap.shutdown()
}
}
我敢肯定的是,执行服务配置必须满足一些具体的要求,但(核心池大小,队列类型)?除非语句A,B和C的执行顺序完全是[B,A,C],否则bootstrap.shutdown()将永远阻塞。三种语句的六种组合中,有三种将核心池大小增加到2个块。如果核心池大小大于2或者SynchronousQueue每个组合都会终止。
哈!好。我将针对3.6.3创建一个新问题。 – 2013-03-23 15:39:54
https://github.com/netty/netty/issues/1200 – 2013-03-23 15:59:19