Netty 4: high and low write watermarks

拜拜、爱过 提交于 2019-12-02 23:54:07
Michael Zhavzharov

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 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.

WRITE_BUFFER_HIGH_WATER_MARK and WRITE_BUFFER_LOW_WATER_MARK

options and relative methods in ChannelConfig are deprecated.

.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1, 2))

that's how you do it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!