Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top