Netty 4:高写和低写水印 [英] Netty 4: high and low write watermarks

查看:769
本文介绍了Netty 4:高写和低写水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netty 4.我看到Netty服务器的下列选项:WRITE_BUFFER_HIGH_WATER_MARK和WRITE_BUFFER_LOW_WATER_MARK。

I am working with Netty 4. I see folowing options of Netty server: WRITE_BUFFER_HIGH_WATER_MARK and WRITE_BUFFER_LOW_WATER_MARK.

官方网页相关文章链接到 Norman Maurer的Ne​​tty最佳实践(带视频的幻灯片)。其中一个幻灯片如下所示:

The official page Related articles has link to Netty best practices (slides w/ video) by Norman Maurer. One of slides looks like this:

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

并有此前言:


设置理智的WRITE_BUFFER_HIGH_WATER_MARK和WRITE_BUFFER_LOW_WATER_MARK

Set sane WRITE_BUFFER_HIGH_WATER_MARK and WRITE_BUFFER_LOW_WATER_MARK

但是什么是WRITE_BUFFER_HIGH_WATER_MARK和WRITE_BUFFER_LOW_WATER_MARK?以及如何将它们设置为理智

But what is it WRITE_BUFFER_HIGH_WATER_MARK and WRITE_BUFFER_LOW_WATER_MARK? And how to set them to be sane?

我没有找到任何明确的信息。感谢您的帮助。

I did not find any clear information. Thanks for your help.

推荐答案

有关水印的一些信息来自文章:

Some information about watermarks from this article:


例如,假设您在服务器端有一个任务队列,即
由客户端填充并由后端处理。如果客户端发送任务
太快,队列长度就会增加。人们需要引入名为高水印和低水印的
。如果队列长度大于
而不是高水位停止从套接字读取并且队列长度将减少
。当队列长度小于低水位时,再次从套接字开始
读取任务。

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似乎是真的,因为这个 JavaDoc for ChannelConfig 说:

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


如果写缓冲区中排队的字节数超过 writeBufferHighWaterMark value,
Channel.isWritable()将开始返回false。

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

对于低水印:


一旦排队的字节数写入缓冲区超过了高
水印,然后跌落到此值以下,
Channel.isWritable()将再次返回true。

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.

这篇关于Netty 4:高写和低写水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆