netty 4中服务器端和客户端高低写水印选项的区别
Difference between server side and client side high and low write watermarks options in netty 4
Netty best practices (slides w/ video) by Norman Maurer 引入了 WRITE_BUFFER_HIGH_WATER_MARK
和 WRITE_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);
Whosebug 上还有一个关于此主题的 discussion。但是有些细节我还是不太确定。
客户端设置的高低写水印选项控制客户端到服务器写入队列的行为,服务器端选项控制服务器到客户端写入队列的行为吗?
也就是说如果设置了服务器端高水位线选项,那么当客户端接收速度慢,之前写入的数据已满队列时,向客户端写入数据的服务器端通道变得不可写?客户端选项反之亦然。
顺便说一句,我使用的是 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.isWritable 方法开始返回 false,直到通道再次达到低水位线。
但是,如果我们不 check/ignore channel.isWritable 状态并在达到高水位线后继续写入通道,最终可能会导致 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?
完全正确。
Netty best practices (slides w/ video) by Norman Maurer 引入了 WRITE_BUFFER_HIGH_WATER_MARK
和 WRITE_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);
Whosebug 上还有一个关于此主题的 discussion。但是有些细节我还是不太确定。
客户端设置的高低写水印选项控制客户端到服务器写入队列的行为,服务器端选项控制服务器到客户端写入队列的行为吗?
也就是说如果设置了服务器端高水位线选项,那么当客户端接收速度慢,之前写入的数据已满队列时,向客户端写入数据的服务器端通道变得不可写?客户端选项反之亦然。
顺便说一句,我使用的是 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.isWritable 方法开始返回 false,直到通道再次达到低水位线。
但是,如果我们不 check/ignore channel.isWritable 状态并在达到高水位线后继续写入通道,最终可能会导致 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?
完全正确。