如何在 JBoss-Netty 中使用无限的帧大小而不浪费内存?
我探索 netty 在虚拟机之间进行对象通信。我使用 ObjectEncoder
& ObjectDecoder
分别序列化这些。
我很快发现这个解决方案仅限于最大 1MB 大小的对象。由于我打算传达更大的对象,并且我不打算限制此大小,因此我使用 Integer.MAX_VALUE
来设置最大帧长度。
不幸的是,看起来这个值被选取来初始化一些缓冲区,从而导致不必要的GC,并且很可能出现OutOfMemory。
有没有办法在使用 DynamicChannelBuffers 时创建无限的 ObjectEncoder/Decoder,这样就不会浪费太多内存?
I explore netty to communicate Objects between VMs. I use ObjectEncoder
& ObjectDecoder
respectively to serialize these.
I quickly found out that this solution is limited to max 1MB-sized objects. As I intend to communicate larger objects and given 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 picked up to initialize some buffers, thus resulting in unnecessary GC-ing and very likely in OutOfMemory.
Is there a way to create an unlimited ObjectEncoder/Decoder while using DynamicChannelBuffers so that not too much memory is wasted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ObjectDecoder
扩展了LengthFieldBasedFrameDecoder
,后者又扩展了FrameDecoder
。FrameDecoder
管理解码缓冲区,它使用初始容量为256
的动态缓冲区。但是,一旦收到大对象,动态缓冲区就会自行扩展,但永远不会收缩。如果您有多个交换大型对象的连接,您的
ObjectDecoder
最终都会有一个非常大的缓冲区,可能会导致OutOfMemoryError
。该问题已于上周得到修复,新版本 (3.2.7.Final) 将于本周发布。
ObjectDecoder
extendsLengthFieldBasedFrameDecoder
which extendsFrameDecoder
.FrameDecoder
manages the decode buffer and it uses a dynamic buffer with initial capacity of256
.However, once you receive a large object, the dynamic buffer expands itself, but never shrinks. If you have multiple connections that exchange large objects, your
ObjectDecoder
will all have a very large buffer eventually, potentially leading toOutOfMemoryError
.This issue has been fixed last week and a new release (3.2.7.Final) will be released this week.