java - Netty 4中服务器端和客户端高低写水印选项的区别

标签 java netty

Netty best practices (slides w/ video) by Norman Maurer引入了WRITE_BUFFER_HIGH_WATER_MARKWRITE_BUFFER_LOW_WATER_MARK选项。它还给出了示例:

//Server
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
bootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);

//Client
Bootstrap bootstrap = new Bootstrap();
bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);

还有另一个discussion关于 StackOverflow 上的这个主题。但我仍然不确定一些细节。

客户端中设置的高和低写入水印选项是否控制从客户端写入到服务器的队列的行为,而服务器端选项是否控制从服务器写入客户端的队列的行为?

也就是说,如果设置了服务器端高水位线选项,那么当客户端接收缓慢并且之前写入的数据已经填满队列时,向客户端写入数据的服务器端 channel 将变得不可写?对于客户端选项反之亦然。

顺便说一句,我使用的是 netty 4.1.0CR。

最佳答案

Which means if the server side high watermarks options is set, then the server side channel which writes data to client becomes not writable when the client receives slowly and the previously written data has filled the queue? And vice versa for client side options.

一旦 channel 中的数据达到高水位线,channel.isWritable方法开始返回 false,直到 channel 再次达到低水位线。

但是,如果我们不检查/忽略 channel.isWritable状态并继续写入 channel ,即使达到高水位线后,它最终可能会导致 OOM 错误,如前两张幻灯片所示。

更新

Do the high and low write watermarks options set in client side control the behaviour of the queue written from client to server, and the server side options control the behaviour of the queue written from server to client?

这绝对是真的。

关于java - Netty 4中服务器端和客户端高低写水印选项的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35569017/

相关文章:

java - SOAP org.xmlpull.v1.XmlPullParserException : expected: START_TAG

java - 在 Netty 中处理多格式数据

java - Netty channel.write 不写消息

java - 具有多个数字的正则表达式(前瞻)

java - 就处理能力和内存使用而言,使用局部变量相对于实例变量有什么好处,反之亦然

java - hibernate 外键未在 SaveOrUpdate 上更新

java - 如何用netty4实现高吞吐量服务器

java - 如何使用netty在单独的线程池中执行业务逻辑处理程序

java - 使用netty动态传输数据

java - JVM 语言互操作性