1

I'm writing highly loaded client/server application. There are cases on some OSes, when connection is lost, but netty doesn't know about it (due to TCP/IP protocol doesn't have pinging). So I decided to implement connection pinging on my app level.

Then I've faced the next problem: ping from server can not reach client and back during reasonable time in cases when server sends too much messages to the client via slow network connection (write buffer high water mark is rather big, several MB). In this case server breaks connection despite its alive and working.

So I've decided to look on IO processing while pinging as well. So I could consider as normal the next situation: when ping is timed out, but bytes from server are still being processed and written to the socket.

However, looks like its impossible in netty to count actual written bytes to socket and measure last to socket write time, because NioSocketChannel.doWrite(ChannelOutboundBuffer in) doesn't have any callbacks for that. And I don't want to hack the netty code by overwriting somehow NioSocketChannel doWrite method.

I'm using netty 4.0.42.

Any help is appreciated!

Sangram Badi
  • 4,054
  • 9
  • 45
  • 78
Mark Vilkel
  • 55
  • 1
  • 5
  • Have you looked at http://stackoverflow.com/questions/21358800/tcp-keep-alive-to-determine-if-client-disconnected-in-netty – Chris O'Toole Nov 17 '16 at 12:01
  • Yes, its elegant, but might work slower, because write listener is added on each message promise inside IdleStateHandler.write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) – Mark Vilkel Nov 17 '16 at 14:37
  • It sounds like the network is your bottleneck, not CPU. I would try getting something that works first, and then figure out where to optimize. – Chris O'Toole Nov 17 '16 at 14:51
  • Yes, that is true. Thank you for your help, it works fine for me. – Mark Vilkel Nov 17 '16 at 15:09

0 Answers0