Netty and TCP Flow Control

430 views
Skip to first unread message

Nipun Arora

unread,
Mar 12, 2017, 8:18:32 PM3/12/17
to Netty discussions
I am trying to understand netty and it's relationship with TCP Flow control (since it has non-blocking I/O).
Also, I am trying to understand, outbound channel buffer's use and watermarks. How does it come into play if I only use WriteandFlush().

As a test case, I have a netty server which writes to a client, the client is blocked (essentially has a sleep of 10 seconds between each read)

- Under normal I/O TCP sender would be throttled (sending is slowed down because of flow control) if the receiver is blocked, this is not the case here. The sender seems to keep writing and flushing data on each send. Where is this data being written? Is there going to be Flow control in the netty's flush() as well? 

- Is it is being written to an OS or TCP buffer, does netty channel have an internal buffer as well? If so how can I configure it?

- I track bytesBeforeUnwritable but they do not seem to be decreasing even after sending a lot of data. (I only use writeandflush() )

- What is the default High and Low Watermark? I have not set anything in my application. Is there any way to use this instead?


Code below:

     @Override
       
public void channelRead(final ChannelHandlerContext ctx, Object buf) {
   
if (server3OutboundChannel.isActive()) {
                server3OutboundChannel
.writeAndFlush(msg)
                       
.addListener(new ChannelFutureListener() {
                   
@Override
                   
public void operationComplete(ChannelFuture future) {
                       
if (future.isSuccess()) {
                           
// was able to flush out data, start to read the next chunk
                           
System.out.println(server3OutboundChannel.bytesBeforeUnwritable());
                            ctx
.channel().read();
                       
} else {
                            future
.channel().close();
                       
}
                   
}
               
});
           
}
   
}


Could anyone please let me know?

Thanks
Nipun

Nipun Arora

unread,
Mar 14, 2017, 3:35:39 AM3/14/17
to Netty discussions
Could someone please respond and let me know regarding this? 


i checked after running a test-case by completely blocking the receive in the server. netty is basically used as a proxy between the client and server. The client kept sending a message in a loop and the message was also printed out to System.out along with a counter. The client eventually stops sending any more messages. The proxy keeps forwarding these messages and "never" becomes unwritable, nor does the bytebeforeunwritable decrease

I have also posted this question on SO, but the answer that I have received does not match my testing, so I would like to understand further.


I will really appreciate any response.

Thanks
Nipun

naik...@gmail.com

unread,
Sep 18, 2018, 7:02:14 PM9/18/18
to Netty discussions
Not certain... but I suspect the channel buffer becomes 'not writable' when the write buffers are full. Here you are using writeAndFlush which flushes the buffer. Try this with write() instead. 
Reply all
Reply to author
Forward
0 new messages