Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netty client bounded queue discard policy

Tags:

netty

Hitting an OutMemoryError connecting to 3rd party server which cannot process requests fast enough.

Tried NioClientSocketChannelFactory to pass in the executor service with the bounded queue and discard policy (ThreadPoolExecutor.DiscardPolicy) but still got OutOfMemoryError.

What am I missing?

Thanks

like image 495
user432024 Avatar asked Jan 19 '23 03:01

user432024


1 Answers

If your client-side Netty channel's write buffer fills up and the server is not reading it fast enough, you will see OutOfMemoryError on the client side. To avoid that, you have to stop writing if Channel.isWritable() returns false. You will be notified with a channelInterestOpsChanged event when the status of Channel.writable' changes. Then, you can check again ifChannel.isWritable()returnstrue` and continue writing.

If it is OK to discard the pending data, I would simply not call Channel.write() if Channel.isWritable() returns false.

You can configure when Channel.writable property changes with the watermark properties provided in NioSocketChannelConfig. Also, please take a look into the 'discard' example that uses this technique.

like image 117
trustin Avatar answered Jan 21 '23 22:01

trustin