如何监视Netty EventLoopGroup线程池

时间:2017-10-25 12:35:56

标签: netty threadpool monitoring

我有一个使用Netty构建的服务器,其线程池基于bossGroup / workerGroup模型。哪个是基本的Netty服务器实现:

    EventLoopGroup bossGroup = new NioEventLoopGroup(poolSize);
    EventLoopGroup workerGroup = new NioEventLoopGroup(poolSize);


    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)                 
        .channel(NioServerSocketChannel.class)
        .handler(new LoggingHandler(LogLevel.INFO))
        .childHandler(new TelnetServerInitializer());

    b.bind(PORT);

如果我想监视两个线程池bossGroup和workerPool的活动,那么活动线程计数和池大小是什么?我应该怎么做?

对于Java的ThreadPoolExecutor,我有:

ThreadPoolExecutor.getActiveCount()
ThreadPoolExecutor.getQueue.size() 

对于EventLoopGroup,它还扩展了ExecutorService。有没有办法获取这些信息?

1 个答案:

答案 0 :(得分:1)

如果您使用NioEventLoopGroup / EpollEventLoopGroup / KQueueEventLoopGroup,则可以使用SingleThreadEventExecutor.pendingTasks()

https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java#L308

您可以通过以下方式获取所有执行者:

EventLoopGroup.iterator()