背景下尋求建議: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