java - Netty 客户端接收消息延迟
问题描述
1.场景说明:设备发送数据到Netty Server(大约##20ms间隔##),Netty Server将msg转发给客户端##立即##(IOS或Android)。2.关联业务代码ctx.writeAndFlush(msg)
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
int writeSpinCount = -1;
boolean setOpWrite = false;
for (;;) {
//Get the data of the first node that needs to be flushed
Object msg = in.current();
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
boolean done = false;
long flushedAmount = 0;
// Get the number of spin lock iterations
if (writeSpinCount == -1) {
writeSpinCount = config().getWriteSpinCount();
}
// Spin, write out the current node
for (int i = writeSpinCount - 1; i >= 0; i --) {
int localFlushedAmount = doWriteBytes(buf);
if (localFlushedAmount == 0) {
setOpWrite = true;
break;
}
flushedAmount += localFlushedAmount;
if (!buf.isReadable()) {
done = true;
break;
}
}
in.progress(flushedAmount);
// After writing, delete the current node
if (done) {
in.remove();
} else {
break;
}
}
}
}
protected int doWriteBytes(ByteBuf buf) throws Exception {
final int expectedWrittenBytes = buf.readableBytes();
return buf.readBytes(javaChannel(), expectedWrittenBytes);
}
3.issue netty Server 可以及时接收设备数据,netty Server 也可以及时将数据写入 Socket Buffer。但是Netty客户端收到消息延迟!!!(比如5s延迟)
4.服务器带宽配置 Inbound 100M/bps bit per seconds。每秒出站 5M/bps 比特。
解决方案
客户端长度加壳引起的问题。
推荐阅读
- javascript - 如何延迟父组件的渲染,直到子组件中的 setState 完成?
- flutter - 如何制作像 Google 一样的 TextFormField?
- html - 覆盖 flex 属性以在 HTML 中手动设置跨度宽度的方法
- java - java.lang.OutOfMemoryError: Java heap space 在java中做加密时如何处理?
- mysql - 当我尝试基于同一列进行两次排序时,为什么 SQL 不会抛出错误?
- azure-data-explorer - 指定 Azure blob 虚拟文件夹而不是文件以引入 Kusto
- c++ - 声明一个变量,该变量具有 c++ 或 c 中的值,在程序终止时不会被销毁
- latex - 如何制作自定义的 LaTeX 符号
- macos - 将 PCL 升级到 .NET Standard 2.0 后在 Mac 上构建错误
- r - R中的标准偏差