欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Netty 高级功能(三):性能指标收集和监控

最编程 2024-04-17 07:30:33
...

1、Netty I/O线程池性能统计

线程池(workGroup)中待线程(NioEventLoop)处理的消息队列(积压队列),一个NioEventLoop对应一个线程,待处理的消息队列越大,说明NioEventLoop中线程越忙,通过这个指标可以表明I/O线程池的性能状况。

image.png

2、Netty 发送队列积压消息数
image.png

3、Netty消息读取速度性能统计
image.png

4、Netty 消息发送速度性能统计

在netty流控那一章节,我们已经看过消息发送时的源码,当我们调用channle的write方法时,消息先进入一个队列(链表),再写入TCP缓存区,所以当我们统计消息发送速度时,如果在调用write方法之后就对发送的字节数做计数,统计结果就不准备。

image.png
image.png
public void responseCmd(SocketChannel socketChannel, Byte[] response) {
        //write是异步的
        ChannelFuture channelFuture = socketChannel.writeAndFlush(response);
        channelFuture.addListener(new ChannelFutureListener(){
          @Override public void operationComplete(ChannelFuture future) throws Exception
          {
              //当触发回调时,说明消息已经写入缓冲区队列
              totalSendBytes.getAndAdd(response.length);
          }
        });
    }