netty内存泄露分析方法

  |   0 评论   |   0 浏览

背景

我有一个应用,运行一段时间后,会发现内存OOM。

看堆栈,是:

"nioEventLoopGroup-2-1" #30 prio=10 os_prio=0 tid=0x00007fb2706cf800 nid=0x19e runnable [0x00007fb2a834a000]
   java.lang.Thread.State: RUNNABLE
        at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
        at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
        at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
        at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
        - locked <0x000000056a86f3e8> (a io.netty.channel.nio.SelectedSelectionKeySet)
        - locked <0x000000056a86f358> (a java.util.Collections$UnmodifiableSet)
        - locked <0x0000000569ff0cb0> (a sun.nio.ch.EPollSelectorImpl)
        at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
        at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
        at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:817)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:460)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)

   Locked ownable synchronizers:
        - None

其实netty提供了内存泄露分析方法的。

分析方法

启动参数

启动增加参数:
-Dio.netty.leakDetectionLevel=advanced