【fix】 优化读写缓冲区设置为度缓冲区2m 写1m 低水位1m 高水位2m

This commit is contained in:
wujiawei
2024-09-09 15:51:01 +08:00
parent 4ec1401712
commit 10d2d74ca3
18 changed files with 208 additions and 63 deletions

View File

@ -0,0 +1,46 @@
package org.framework.lazy.cloud.network.heartbeat.common.filter;
import io.netty.channel.*;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class DebugChannelInitializer<C extends Channel> extends ChannelInitializer<C> {
protected abstract void initChannel0(C ch) throws Exception;
/**
* This method will be called once the {@link Channel} was registered. After the method returns this instance
* will be removed from the {@link ChannelPipeline} of the {@link Channel}.
*
* @param ch the {@link Channel} which was registered.
* @throws Exception is thrown if an error occurs. In that case it will be handled by
* {@link #exceptionCaught(ChannelHandlerContext, Throwable)} which will by default close
* the {@link Channel}.
*/
@Override
protected void initChannel(C ch) throws Exception {
initChannel0(ch);
ChannelConfig config = ch.config();
Class<?> filterClass = this.getClass();
// 获取默认配置
Integer defaultRcvBufSize = config.getOption(ChannelOption.SO_RCVBUF);//读缓冲区为
log.debug("filter:{},defaultRcvBufSize:{}", filterClass, defaultRcvBufSize);
Integer defaultSndBufSize = config.getOption(ChannelOption.SO_SNDBUF);//写缓冲区
log.debug("filter:{},defaultSndBufSize:{}", filterClass, defaultSndBufSize);
Integer defaultConnectTimeoutMillis = config.getOption(ChannelOption.CONNECT_TIMEOUT_MILLIS);// 连接时常
log.debug("filter:{},defaultConnectTimeoutMillis:{}", filterClass, defaultConnectTimeoutMillis);
RecvByteBufAllocator recvByteBufAllocator = config.getOption(ChannelOption.RCVBUF_ALLOCATOR);// 获取读缓冲区大小
log.debug("filter:{},recvByteBufAllocator:{}", filterClass, recvByteBufAllocator);
int writeBufferLowWaterMark = config.getWriteBufferLowWaterMark();
int writeBufferHighWaterMark = config.getWriteBufferHighWaterMark();
log.debug("filter:{}, high water mark: {}", filterClass,writeBufferHighWaterMark);
log.debug("filter:{}, low water mark: {}", filterClass,writeBufferLowWaterMark);
}
}

View File

@ -14,6 +14,8 @@ public class ChannelAttributeKeyUtils {
private static final AttributeKey<Integer> OUT_FLOW = AttributeKey.newInstance("outFlow");
private static final AttributeKey<Integer> IN_FLOW = AttributeKey.newInstance("inFlow");
private static final AttributeKey<Channel> NEXT_CHANNEL = AttributeKey.newInstance("nextChannel");
/**
* 为通道绑定 访客属性
@ -131,4 +133,25 @@ public class ChannelAttributeKeyUtils {
public static Integer getVisitorPort(Channel channel) {
return channel.attr(VISITOR_PORT).get();
}
/**
* 为通道绑定 下一个通道
*
* @param channel 通道
* @param nextChannel 下一个通道
*/
public static void buildNextChannel(Channel channel, Channel nextChannel) {
channel.attr(NEXT_CHANNEL).set(nextChannel);
}
/**
* 获取 通道中下一个通道
*
* @param channel 通道
*/
public static Channel getNextChannel(Channel channel) {
return channel.attr(NEXT_CHANNEL).get();
}
}