繁体   English   中英

Netty 客户端接收消息延迟

[英]Netty client receives the message delay

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 比特。

客户端长度加壳引起的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM