Java 如何在netty中动态管理CPU负载?
好了,EventLoops由执行者支持,“子/工”由EventLoops支持,“家长/老板”管理频道上“子/工”的激活Java 如何在netty中动态管理CPU负载?,java,multithreading,netty,Java,Multithreading,Netty,好了,EventLoops由执行者支持,“子/工”由EventLoops支持,“家长/老板”管理频道上“子/工”的激活 在某个地方是否有阻塞队列来容纳传入的请求,直到有一个子节点可以处理它们 一个子系统将创建多少线程 在支持子线程池的队列已满的情况下,如何确保拒绝向父线程传入的通道事件 很难辨别netty的底层线程池在何处/如何配置 我可以找出3,如果有人可以提供一些细节1和2 是的,NioEventLoopGroup扩展了multi-threadEventExecutor组,该组将其Event
NioEventLoopGroup
扩展了multi-threadEventExecutor组
,该组将其EventExecutor[/code>子项创建为新的SingleThreadEventExecutor[nThreads]
。此SingleThreadEventExecutor
的TaskQueue
是一个LinkedBlockingQueue()
DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
"io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
您可以将io.netty.eventLoopThreads
作为JVM启动参数传递
您还可以在NioEventLoopGroup()的构造函数中输入线程数量。我们以此为例:
private final static int BOSS_THREADS = 1;
private final static int MAX_WORKER_THREADS = 12;
Integer.MAX\u值
线程EventLoopGroup bossGroup = new NioEventLoopGroup(BOSS_THREADS);
EventLoopGroup workerGroup = new NioEventLoopGroup(calculateThreadCount());
private int calculateThreadCount() {
int threadCount;
if ((threadCount = SystemPropertyUtil.getInt("io.netty.eventLoopThreads", 0)) > 0) {
return threadCount;
} else {
threadCount = Runtime.getRuntime().availableProcessors() * 2;
return threadCount > MAX_WORKER_THREADS ? MAX_WORKER_THREADS : threadCount;
}
}