Analysis of Netty4 reading and writing water level control

Source: Internet
Author: User

On the server, see what the default is.

Configure high and low write watermarks

Set Sane Write_buffer_high_water_mark and Write_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 had a queue of tasks on the server side that was 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-Watermark and low watermark. If Queue Length is greater than-watermark stop reading from sockets and queue length would decrease. When the queue length becomes less than low watermark start reading the tasks from sockets again.

Note, to-make it possible-clients to adapt-speed your process tasks (actually to adapt window size) One shouldn ' t ma Ke a big gap between and low watermarks. From the other side small gap means you'll be a 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, C Hannel.iswritable () would return true again.

About Sanity, I think, it's relative question, that depends on information that's sending through the channel and H OW often. There is no strict rules for who values you must define for that variables. So, I think, you must found your own values in practice. Slides show one of the examples for that

You can notified for this changes by override the Channelwritabilitychanged (...) method in Channelinboundhandler.

This interface can be implemented to monitor water level changes.


Analysis of Netty4 reading and writing water level control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.