Happy Lemon
Happy Lemon

Reputation: 95

How to monitor Netty EventLoopGroup threadpool

I have a server built with Netty and its threadpool is based on bossGroup/workerGroup model. Which is the basic Netty server implementation:

    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);

If I would like to monitor activity of the two threadpool bossGroup and workerPool, something like the active thread counts and pool size? How should I do?

For Java's ThreadPoolExecutor, I have the:

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

For EventLoopGroup, it also extends ExecutorService. Is there a way to get those information?

Upvotes: 3

Views: 2778

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23557

If you use NioEventLoopGroup / EpollEventLoopGroup / KQueueEventLoopGroup you can use SingleThreadEventExecutor.pendingTasks() :

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

You can obtain all the executors via:

EventLoopGroup.iterator()

Upvotes: 3

Related Questions