netty 服务端向客户端推送大量数据,当服务端sendbuf 达到最高水位后(receivebuf空闲),不再继续推送数据,服务端sendbuf 却一直不下降,就卡在一个固定值了(64240),好像假死了,tcpdump 抓包 服务端能收到客户端的心跳数据,就是不能发送数据(服务netty channel iswriteble =false ,sendbuf 还是固定值)
查了下服务客户端的负载也在可接受的范围
netty 版本 4.1.66
服务端截图:
客户端截图:
下面是向客户端转发推送数据的代码片段:
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel channel = ctx.channel();
ProxyChannel userChannel=GlobalChannelGroup.getUserChannelByDispatcherShortId(channel.id().asShortText());
Channel uc=userChannel.getChannel();
if(uc!=null) {
if(uc.isWritable()&&uc.isActive()) {
try {
//ChannelFuture future=uc.writeAndFlush(msg);
ChannelFuture future= uc.writeAndFlush(safeDuplicate(msg));
future.addListener((future1 -> {
if (future1.isSuccess()) {
LOGGER.info("代理-转发-成功-代:{}-用:{}-代:{}-用:{}",channel.id().asShortText(),uc.id().asShortText(),channel.remoteAddress(),uc.remoteAddress());
} else {
LOGGER.info("代理-转发-失败-代:{}-用:{}-代:{}-用:{}-{}--{}",channel.id().asShortText(),uc.id().asShortText(),channel.remoteAddress(),uc.remoteAddress(),uc.isActive(),future1.cause());
}
}));
}finally{
//LOGGER.info("-------------------------------------------V1");
}
}else {
LOGGER.warn("channel:{},缓存已满-距离需消耗:{}--代理:{}-用户:{}", uc.id().asShortText(), uc.bytesBeforeWritable(),channel.remoteAddress(),uc.remoteAddress());
}
}else {
LOGGER.info("获取用户链接不存在-或已经关闭---{}",channel.id().asShortText());
}
}