mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.82k stars 1.65k forks source link

OutOfMemory issue #487

Open Maxinim opened 7 years ago

Maxinim commented 7 years ago

Hi there,

I'm working on developping my application using netty-socketio, but it seems to always finish with an out of memory error. If i anayze the heap dump, I see that the culprits are netty buffers. See attached heap dump dominator tree in Eclipse MAT.

The main problem is io.netty.buffer.PoolArena$HeapArena. You can see inside some exchanged messages in the PoolChunk byte array : {'join' {'agent': true....

Is there a way to limit the space used by netty, or telling it not to store messages, or to store them somewhere else ? Could you help me with this memory "leak" (not sure it's a leak, may be something i don't do correctly)?

hprof_analysis
pablojr commented 7 years ago

@Maxinim you may want to take a look at this Netty issue or this one also as they mention a way to change Netty's default allocator, along with some suggested JVM parameters.

Maxinim commented 7 years ago

@pablojr Thanks for the info. I'll try the ChannelConfig tip, but I don't know how to set this on Netty-socketio. I'll have to search. By the way, this bug is linked to the memory store used, or it will happen whatever the store used ?

I'd like to destroy sessions also on disconnection, but I don't know how to do this.

Maxinim commented 7 years ago

@pablojr (or anyone), I don't seem to see any reference to ChannelConfig in netty-socketio. Does soemone know how to configure this in netty-socketio server ?

lovelyelfpop commented 6 years ago

@Maxinim Have you solved this problem?

Maxinim commented 6 years ago

Hi @lovelyelfpop, I'm not sure yet. Currently I created a fork of this repository, and made a change to use unpooled byte buffers. But I had to work on something else in the meantime, so not sure it helped. Currently no OOM since I started to work on my project again (yesterday...), I'll wait and see.

In SocketIOServer.java, line 171 (or maybe 170, I think I added an import too), I replaced this :

bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(config.getTcpReceiveBufferSize()));

by that :

bootstrap.childOption(ChannelOption.ALLOCATOR, new UnpooledByteBufAllocator(true));

Maxinim commented 6 years ago

@lovelyelfpop I talked too fast... I just got an OOM right now. So my fix didn't work. Anyone has anymore input on this ?

suood commented 4 years ago

@lovelyelfpop I talked too fast... I just got an OOM right now. So my fix didn't work. Anyone has anymore input on this ?

Have you fixed this ? I've got this trouble too!