rocketmq的remoting.log日志一直在打印如下警告日志:
2024-06-11 10:51:16 WARN NettyServerCodecThread_1 - Channel[192.168.1.2:53662] auto-read is disabled, bytes to drain before it turns writable: 35571
2024-06-11 10:51:16 INFO NettyServerCodecThread_1 - Channel[192.168.1.2:53662] turns writable, bytes to buffer before changing channel to un-writable: 65536
2024-06-11 10:51:40 WARN NettyServerCodecThread_4 - Channel[192.168.1.2:47966] auto-read is disabled, bytes to drain before it turns writable: 61404
2024-06-11 10:51:40 WARN NettyServerCodecThread_4 - Channel[192.168.1.2:47966] auto-read is disabled, bytes to drain before it turns writable: 61404
2024-06-11 10:51:40 INFO NettyServerCodecThread_4 - Channel[192.168.1.2:47966] turns writable, bytes to buffer before changing channel to un-writable: 65536
2024-06-11 10:52:28 WARN NettyServerCodecThread_4 - Channel[192.168.1.2:47966] auto-read is disabled, bytes to drain before it turns writable: 61404
2024-06-11 10:52:28 WARN NettyServerCodecThread_4 - Channel[192.168.1.2:47966] auto-read is disabled, bytes to drain before it turns writable: 61404
2024-06-11 10:52:28 INFO NettyServerCodecThread_4 - Channel[192.168.1.2:47966] turns writable, bytes to buffer before changing channel to un-writable: 65536
2024-06-11 10:52:52 WARN NettyServerCodecThread_1 - Channel[192.168.1.2:53662] auto-read is disabled, bytes to drain before it turns writable: 0
2024-06-11 10:52:52 INFO NettyServerCodecThread_1 - Channel[192.168.1.2:53662] turns writable, bytes to buffer before changing channel to un-writable: 65536
解决办法
在配置文件加入如下配置:
# 设置TCP发送缓冲区大小
serverSocketSndBufSize=65536
# 设置TCP接收缓冲区大小
serverSocketRcvBufSize=65536
# 设置写缓冲区的高水位标记
writeBufferHighWaterMark=4194304
# 设置写缓冲区的低水位标记
writeBufferLowWaterMark=1048576
原因
日志信息显示了一些关于RocketMQ使用Netty通信框架时的通道(Channel)状态。这里的日志信息主要涉及以下几个关键点:
1、Auto-read is disabled: 当auto-read被禁用时,Netty不会自动从网络中读取数据,直到明确命令它这么做。这可能是为了控制数据流,防止内存溢出。
2、Bytes to drain before it turns writable: 这表示在通道可以再次开始写操作之前,还需要从通道中排出多少字节的数据。这是流控制的一种形式,通常用于防止发送方过快地发送数据而接收方来不及处理。
3、Turns writable, bytes to buffer before changing channel to un-writable: 当通道变为可写时,会记录可以缓冲的字节数,直到通道再次变为不可写。这表明了通道从不可写状态转换到可写状态的阈值。