High/Low water marks on NIO channels

"이희승 (Trustin Lee)" trustin at gmail.com
Mon Jan 10 00:53:14 EST 2011


Hi Iain,

Thanks again for pointing this problem out.  Your pull request has been
processed. :-)

Cheers,
Trustin

On 11/19/2010 11:28 PM, Iain McGinniss wrote:
> Hello all,
> 
> I am currently getting my HTTP tunnel code in shape for being pulled
> into the Netty github repo. In doing this, I am attempting to implement
> a similar feature to the high/low water marks in NioSocketChannels. I
> think I have found a mistake in the documentation:
> 
> http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/socket/nio/NioSocketChannelConfig.html#setWriteBufferHighWaterMark(int)
> 
> What I expected was that "low" water mark indicated the safe level, that
> when the amount of bytes queued to be sent went under this value writing
> could resume (isWriteable() = true). "high" water mark would indicate
> the danger level, than when the amount of bytes queued to be sent went
> over this value then writing should stop (isWriteable() = false). The
> documentation says the inverse of this.
> 
> Looking at the code in NioSocketChannel, I believe that the code is
> actually doing things the way I would expect. When the number of bytes
> in message queue exceeds the high water mark, the "high water mark
> counter" is incremented:
> 
> https://github.com/iainmcgin/netty/blob/master/src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java#L223
> 
> When the number of bytes drops beneath the low water mark, the counter
> is decremented:
> 
> https://github.com/iainmcgin/netty/blob/master/src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java#L244
> 
> This counter is then used in getInterestOps() to decide whether we
> should be enable or disable write:
> 
> https://github.com/iainmcgin/netty/blob/master/src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java#L163
> 
> 1. If we had previously exceeded the high water mark (counter > 0) and
> we are still above the low water mark, write remains disabled.
> 2. If we had previously exceeded the high water mark (counter > 0) and
> we are now below the low water mark, write is enabled.
> 3. If we were beneath the high water mark (counter <= 0) and we are
> still below the high water mark, write remains enabled.
> 4. If we were beneath the high water mark (counter <= 0) and we are now
> above the high water mark, write is disabled.
> 
> This is my interpretation of the code in getInterestOps(), based on
> isWriteable() returning (getInterestOps() & OP_WRITE == 0). If someone
> can confirm that I am correct, I will push a change to the documentation
> in my own git repo and a pull request on the main repo.
> 
> Cheers,
> Iain
> 
> 
> 
> 
> _______________________________________________
> netty-dev mailing list
> netty-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-dev

-- 
Trustin Lee, http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 294 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-dev/attachments/20110110/034049f9/attachment.bin 


More information about the netty-dev mailing list