I am trying to understand netty buffers and watermarks.
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? See: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Flow_control
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
- 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 msg) {
if (server2OutboundChannel.isActive()) {
if(server2OutboundChannel.isWritable()) {
server2OutboundChannel.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(server2OutboundChannel.bytesBeforeUnwritable());
ctx.channel().read();
} else {
future.channel().close();
}
}
});
}else{
System.out.println("Channel is no longer writeable");
System.out.println(server2OutboundChannel.bytesBeforeUnwritable());
System.out.println(server2OutboundChannel.bytesBeforeWritable());
}
}
}
Detailed steps to re-create with end-to-end source code:
Clone https://github.com/nipunarora/nettyDuplicator .
Specifically, the proxy code is here:
https://github.com/nipunarora/nettyDuplicator/tree/master/src/main/java/org/columbia/parikshan/proxy
Compile and Build:
mvn package
Start the server
sh scripts/Server.sh 3380
Start the netty proxy
sh scripts/nettyProxy.sh -l 0.0.0.0:3379 -o 127.0.0.1:3380
Start the client
sh scripts/Client.sh 127.0.0.1 3379
send "hello" as std input in client
netty blocks sending after some time and the bytesTillUnwritable do not decrease.