码迷,mamicode.com
首页 > Web开发 > 详细

Netty4 读写水位控制分析

时间:2015-08-30 23:09:25      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:

服务器上看看默认是多少

Configure high and low write watermarks

Set sane WRITE_BUFFER_HIGH_WATER_MARK andWRITE_BUFFER_LOW_WATER_MARK

ServerBootstrap bootstrap = new ServerBootstrap();

bootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);

bootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);  

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

You can notified for this changes by override the channelWritabilityChanged(...) method in ChannelInboundHandler.

可以通过实现这个接口来监听水位的变化。


Netty4 读写水位控制分析

标签:

原文地址:http://blog.csdn.net/jiangguilong2000/article/details/48109963

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!