Netty4 读写水位控制分析

简介: Netty4 读写水位控制分析

服务器上看看默认是多少

Configure high and low write watermarks

Set sane WRITE_BUFFER_HIGH_WATER_MARK andWRITE_BUFFER_LOW_WATER_MARK

ServerBootstrap bootstrap = new ServerBootstrap();

bootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);

bootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);  

For instance, imagine you have a queue of tasks on server side that is filled by clients and processed by backend. In case clients send tasks too quick the length of the queue grows. One needs to introduce so named high watermark and low watermark. If queue length is greater than high watermark stop reading from sockets and queue length will decrease. When queue length becomes less than low watermark start reading tasks from sockets again.

Note, to make it possible for clients to adapt to speed you process tasks (actually to adapt window size) one shouldn't make a big gap between high and low watermarks. From the other side small gap means you'll be too often add/remove sockets from the event loop.

For Netty it seems to be true, because this JavaDoc for ChannelConfig says:

If the number of bytes queued in the write buffer exceeds writeBufferHighWaterMark value,Channel.isWritable() will start to return false.

And for low watermark:

Once the number of bytes queued in the write buffer exceeded the high water mark and then dropped down below this value, Channel.isWritable() will return true again.

About sanity, I think, it is relative question, that depends on information that you are sending through the channel and how often. There is no strict rules for what values you must define for that variables. So, I think, you must found your own values in practice. Slides show you one of the examples for that

You can notified for this changes by override the channelWritabilityChanged(...) method in ChannelInboundHandler.

可以通过实现这个接口来监听水位的变化。

水位的变化控制主要在ChannelOutboundBuffer,

private void decrementPendingOutboundBytes(long size, boolean invokeLater)

private void incrementPendingOutboundBytes(long size, boolean invokeLater)

这两个方法,一般若不是瞬间水位变高,则会很容易消耗水位,使得其在稳定的水平

http://dwz.cn/2cQixx

目录
相关文章
|
6月前
|
Java
【Netty 网络通信】Netty 工作流程分析
【1月更文挑战第9天】Netty 工作流程分析
|
6月前
|
Java Unix Linux
【Netty技术专题】「原理分析系列」Netty强大特性之Native transports扩展开发实战
当涉及到网络通信和高性能的Java应用程序时,Netty是一个强大的框架。它提供了许多功能和组件,其中之一是JNI传输。JNI传输是Netty的一个特性,它为特定平台提供了高效的网络传输。 在本文中,我们将深入探讨Netty提供的特定平台的JNI传输功能,分析其优势和适用场景。我们将介绍每个特定平台的JNI传输,并讨论其性能、可靠性和可扩展性。通过了解这些特定平台的JNI传输,您将能够更好地选择和配置适合您应用程序需求的网络传输方式,以实现最佳的性能和可靠性。
143 7
【Netty技术专题】「原理分析系列」Netty强大特性之Native transports扩展开发实战
netty的异常分析 IllegalReferenceCountException refCnt: 0, decrement: 1
netty的异常分析 IllegalReferenceCountException refCnt: 0, decrement: 1
218 0
|
6月前
|
Java API 索引
Netty Review - ByteBuf 读写索引 详解
Netty Review - ByteBuf 读写索引 详解
188 1
|
6月前
|
前端开发 网络协议 Java
Netty | 工作流程图分析 & 核心组件说明 & 代码案例实践
Netty | 工作流程图分析 & 核心组件说明 & 代码案例实践
331 0
|
运维 Java
高并发下Netty4底层bug导致直接内存溢出分析
高并发下Netty4底层bug导致直接内存溢出分析
191 0
|
编解码 前端开发 Java
源码分析Netty:核心组件及启动过程分析
本篇从实例出发,了解Netty核心组件的概念、作用及串联过程。从概念到设计原理,再到深入了解实现细节,从而能够清晰地掌握Netty的技术细节甚至存在的问题,才能最终更好地支持我们实际的各项业务。
350 0
|
存储 Java Unix
【Netty技术专题】「原理分析系列」Netty强大特性之ByteBuf零拷贝技术原理分析
【Netty技术专题】「原理分析系列」Netty强大特性之ByteBuf零拷贝技术原理分析
196 0
【Netty技术专题】「原理分析系列」Netty强大特性之ByteBuf零拷贝技术原理分析
|
网络协议 前端开发 Java
Netty服务端启动流程分析
Netty服务端启动流程分析
172 0
|
分布式计算 网络协议 Java
Netty实现原理分析
Netty实现原理分析
257 0
Netty实现原理分析