How to use unlimited frame sizes in JBoss-Netty without losing memory?

I am researching netty to bind objects between virtual machines. I use ObjectEncoder and ObjectDecoder respectively to serialize them.

I quickly found that this solution is limited to maximum objects of 1 MB in size. Since I intend to bind large objects and given that I do not intend to limit this size, I used Integer.MAX_VALUE to set the maximum frame length.

Unfortunately, it looks like this value is chosen to initialize some buffers , which leads to unnecessary GC-ing and is very likely in OutOfMemory.

Is there a way to create unlimited ObjectEncoder / Decoder when using DynamicChannelBuffers so as not to lose too much memory?

+4
source share
1 answer

ObjectDecoder extends LengthFieldBasedFrameDecoder , which continues to FrameDecoder . FrameDecoder controls the decoding buffer and uses a dynamic buffer with an initial capacity of 256 .

However, as soon as you get a large object, the dynamic buffer expands, but never shrinks. If you have several connections that exchange large objects, your ObjectDecoder will have a very large buffer in the long run, which potentially leads to an OutOfMemoryError .

This problem was fixed last week, and a new version (3.2.7.Final) will be released this week.

+4
source

Source: https://habr.com/ru/post/1380382/


All Articles