问题描述
afaik,EventLoops由执行者支持,“子代/工人”由EventLoops支持,“父母/老板??”管理频道中“子代/工人”的激活。
在某个孩子可以处理这些请求之前,是否有阻塞队列来保存传入的请求?
一个孩子将创建多少个线程?
如何确保在支持子线程池的队列已满的情况下拒绝父级传入的通道事件?
很难确定netty的基础线程池的配置位置/方式。
如果有人可以提供有关1&2的详细信息,我可以找出3。
1楼
是的,
NioEventLoopGroup
扩展了MultithreadEventExecutorGroup
,后者将其EventExecutor[] children
创建为new SingleThreadEventExecutor[nThreads]
。 此SingleThreadEventExecutor
的TaskQueue
是LinkedBlockingQueue<Runnable>()
。NioEventLoopGroup()的标准构造函数创建默认数量的事件循环线程:
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;
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; } }
我实际上不知道Netty是否具有内置功能。 AFAIK队列仅占用
Integer.MAX_VALUE
线程。