[英]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.