gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:34:36 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com