简体   繁体   中英

Netty client receives the message delay

1.scene description: Device sen data to Netty Server(about ## 20ms intervals ##), Netty Server forward msg to Client ## Immediately ##(IOS or Android). 2.Associated business code 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 The netty Server can receive the device data in time and netty Server can write the data to Socket Buffer in time also. But The Netty client receives the message delay!!!(eg. 5s delay)

4.Server bandwidth configuration Inbound 100M/bps bit per seconds. Outbound 5M/bps bit per seconds.

Client terminal length packer caused by the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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