Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

backpressure - What is Netty closing channel policy if client does read data and application keeps writing?

My application uses Netty 4.x with TCP sockets to distribute the same data to multiple clients. I want my application to tolerate some clients stalls in data receiving, but if client is too slow I want my application to abandon (close) the connection.

If I understand correctly I can achieve this by configuring proper:

  • sendBufferSize (as far as it allowed by underlying OS)
  • ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK .

Netty Channel.write() writes to ChannelOutboundBuffer . The contents of ChannelOutputBuffers is written to NIO SocketChannel. The operating system sends data by TCP to client.

If client does not read its socket on time, the OS socket sendBuffer fills up, then ChannelOutboundBuffer fills up as far as WRITE_BUFFER_HIGH_WATER_MARK is reached. Next the channel gets unwrtitable state (to avoid out of memory).

What is Netty closing channel policy in this situation ? Does Netty close channel if handlers keep writing to it despite it is not writable ?

Thanks in advance for any advise.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Netty's policy is to just notify you and will try again once the channel becomes writable again. It's up to the user to decide what is the right action otherwise. Like for example closing the connection or stop reading etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...