GeezerVison is showing github.com — EPollArrayWrapper.epollWait 100% CPU Usage · Issue #327 · netty/netty
EPollArrayWrapper.epollWait 100% CPU Usage #327DescriptionHi,
I believe I have an issue similar to #302 but on Linux (Ubuntu 10.04) with JDK (1.6.0u30) and JDK(1.7.0u4) using Netty-4.0.0 (Revision: 52a7d28)
The app is proxying connections to backend systems. The proxy has a pool of channels that it can use to send requests to the backend systems. If the pool is low on channels, new channels are spawned and put into the pool so that requests sent to the proxy can be serviced. The pools get populated on app startup, so that is why it doesn't take long at all for the CPU to spike through the roof (22 seconds into the app lifecycle).
The test box has two CPUs, the output from 'top' is below:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8220 root 20 0 2281m 741m 10m R 50.2 18.7 0:22.57 java
8218 root 20 0 2281m 741m 10m R 49.9 18.7 0:22.65 java
8219 root 20 0 2281m 741m 10m R 49.2 18.7 0:22.86 java
8221 root 20 0 2281m 741m 10m R 49.2 18.7 0:22.20 java
Thread Dump for the four NioClient based Worker Threads that are chewing up all the CPU.
"backend-worker-pool-7-thread-1" prio=10 tid=0x00007f5918015800 nid=0x201a runnable [0x00007f5924ba3000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:210)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:65)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <0x000000008be93580> (a sun.nio.ch.Util$2)
- locked <0x000000008be93570> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000008be92548> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
at io.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:55)
at io.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:261)
at io.netty.channel.socket.nio.NioWorker.run(NioWorker.java:37)
at io.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:43)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000008be00748> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
"backend-worker-pool-7-thread-2" prio=10 tid=0x00007f5918012000 nid=0x201b runnable [0x00007f5924b82000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:210)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:65)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <0x000000008be94a28> (a sun.nio.ch.Util$2)
- locked <0x000000008be94a18> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000008be90648> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
at io.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:55)
at io.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:261)
at io.netty.channel.socket.nio.NioWorker.run(NioWorker.java:37)
at io.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:43)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000008be904c8> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
"backend-worker-pool-7-thread-3" prio=10 tid=0x00007f5918007800 nid=0x201c runnable [0x00007f5924b61000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:210)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:65)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <0x000000008be952e0> (a sun.nio.ch.Util$2)
- locked <0x000000008be952d0> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000008be8f858> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
at io.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:55)
at io.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:261)
at io.netty.channel.socket.nio.NioWorker.run(NioWorker.java:37)
at io.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:43)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000008be8f618> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
"backend-worker-pool-7-thread-4" prio=10 tid=0x00007f5918019000 nid=0x201d runnable [0x00007f5924b40000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:210)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:65)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
- locked <0x000000008be003f8> (a sun.nio.ch.Util$2)
- locked <0x000000008be003e8> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000008be00408> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
at io.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:55)
at io.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:261)
at io.netty.channel.socket.nio.NioWorker.run(NioWorker.java:37)
at io.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:43)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Locked ownable synchronizers: - <0x000000008be004e0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
Activityblucas commented on May 16, 2012 ContributorAuthor More actions I've done some googling and it looks like this could be a JDK bug.
Take a look at the thread dump supplied on 13-MAY-2009. It is exactly the same as mine! Although they say the bug has been fixed, it obviously hasn't. Could you please investigate the workaround supplied in the link? They mention cancelling the selector and invoking a selectNow() method. I have NO clue where to do that myself to test if it actually works, so if someone could change it in the repo, I'm more than happy to give it a test.
In fact I've actually found a post by @trustin on this very subject. But it looks like no changes were made back then. Reacted by musoon, XiongQingLiang, QABQ, Sailong Ren, George Li and Nazar blucas commented on May 18, 2012 ContributorAuthor More actions Eirenliel commented on Jun 14, 2012 Please, update. Merged on new server wit j6u33 and now experiencing this bug. Will try to downgrade jre... Eirenliel commented on Jun 14, 2012 It is happens on Netty 3.5.0 Final, 3.2.7 Final and 3.4.7 j6u33 and may be others. twinforces commented on Jul 9, 2012 Yeah, I see this too with UltraESB.
I think its a problem with anything that uses the Non-blocking IO library. incubos commented on Jul 26, 2012 I confirm this bug on Netty 3.3.0 Final (from Akka 2.0.2) & j7u4. vikiitd commented on Aug 2, 2012 Hi,
We are seeing this issue in our production environment also under heavy concurrent load. Are there any updates/fix for this issue. On some forums there are discussions related to this issue being resolved by upgrading jdk, etc. I am not seeing this issue with netty.3.2.4.Final.jar but it is happening consistently with netty3.4.4.Final.jar Does anyone know if there is a work-around for this issue besides downgrading back to 3.2.4 netty jar version.
Thanks in advance! vikiitd commented on Aug 8, 2012 I am observing this issue with Netty-3.2.6.Final.jar also, although less frequently. Is it possible that this issue got introduced before 3.3 or it is not a netty issue at all? trustin commented on Aug 9, 2012 Is there any reliable way to reproduce this problem? Then it would be much easier for me to fix this issue (probably it's more correct to say 'apply workaround'). vrajesh1989 commented on Aug 12, 2012 Hi. This issue is occurring in Netty-3.2.4.Final.jar also. There is no reliable way to reproduce this issue, it is not happening consistently. normanmaurer commented on Aug 23, 2012 Let me see if I can fix this ... normanmaurer commented on Aug 25, 2012 @trustin I think this is because of an epoll bug which still is not fixed or was fixed and is now present again.
Please review the following workaround:
#565
So basically we do the following here:
- check if Selector.select(timeout) returns 0 and complete before the timeout
- if so we increment a counter
- if the counter == 10 we create a new selector and register all the Channels from the old one to the new one and close the old Selector. After that we reset the counter.
- if the counter < 10 we just process
- if Selector.select(timeout) returns > 0 or complete after the timeout we reset the counter
The fix is kind of the same as jetty,grizzly and mina do :) WDYT ? vikiitd commented on Aug 27, 2012 it will be great if we can have the workaround provided by @normanmaurer . The jdk bug seems to be hanging around for sometime now, not sure if it is getting fixed anytime soon. senthilec566 commented on Jul 5, 2017 @normanmaurer - Any work around for this ? Should i try old version of Netty ?? senthilec566 commented on Jul 6, 2017 @normanmaurer - Any findings ? Meantime i will try other version of netty .. Scottmitch commented on Jul 6, 2017 @senthilec566 - your issue is using the Epoll JNI transport but this issue was opened against the NIO transport. Can you open another issue?
Also what is your usage pattern look like? Do you have sockets being opened/closed constantly or just a few that are active? If you take successive snapshots (e..g 20 ish) do you see the stack trace change? Seeing the stack trace at epillWait is not necessarily a problem and can be common (it's how the OS tells us what events are pending and is called frequently). Also a reproducer would be nice. umerpk commented on Oct 26, 2017 We are still having same issue on Java 1.8?
"GS-LRMI-Selector-Read-Thread-0" daemon prio=10 tid=0x00007fdc3d550800 nid=0x7533 runnable [0x00007fdbbafdd000]
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:79)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:87)
- locked <0x0000000572484890> (a sun.nio.ch.Util$2)
- locked <0x00000005724848a0> (a java.util.Collections$UnmodifiableSet)
- locked <0x0000000572484848> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:98)
at com.gigaspaces.lrmi.nio.selector.handler.AbstractSelectorThread.doSelect(AbstractSelectorThread.java:62)
at com.gigaspaces.lrmi.nio.selector.handler.AbstractSelectorThread.run(AbstractSelectorThread.java:51)
at java.lang.Thread.run(Thread.java:744)
Locked ownable synchronizers:
- None Reacted by Dmitry Bedrin, Alik Elzin, yarondav, Hao Wang, zhengfh, rohitsahay2000, Ximo Guanter, Siarhei Krukau, Simon Schärer, George Li and 2 more rohitsahay2000 commented on Nov 13, 2018 Facing the same issue with jdk 1.8, netty 4.1.25. The below screenshot was taken when the thread count already hit 1450 (starting from 200)

The event loop group thread count keeps on increasing leading to very high cpu usage and unresponsive container inspite of closing them regularly.
One of the typical threads (having lots of instances) from jstack
nioEventLoopGroup-8870-1 tid=13320
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:281)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:105)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:98)
- locked <0x4f8900cd> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x83732742> (a java.util.Collections$UnmodifiableSet)
- locked <0x288f21af> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:109)
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:756)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:411)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:811)
Locked ownable synchronizers:
- None
Reacted by Siarhei Krukau and George Li VaughnVernon commented on Jan 30, 2020 Hi All, We have hit this problem in a different project (not using Netty) and are looking for a fix/workaround. This only happens on Linux. We would really appreciate some help in learning how you solved this. Would someone please summarize the solution and source files involved? Sorry, it's difficult to piece together what finally worked given all the related discussions/issues.
vlingo/xoom-wire#28 atorr0 commented on Apr 8, 2020 Hi all,
The epoll bug is a well-known one with Java NIO framework, that seems fixed in NIO2.
I hope Netty not having to delve into JNI/JNA/etc. to fix it, but in this case maybe you can even improve it.
More info on #2515 Workeryuan commented on Mar 11, 2021 We are still having same issue on Development environment jdk1.8,Operating environment jre 1.2.
#27 daemon prio=5 os_prio=0 tid=0x00007f6cc41f3000 nid=0xbc59 runnable [0x00007f6cd69f4000]
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 <0x00000006c08856c8> (a sun.nio.ch.Util$3)
- locked <0x00000006c08856d8> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000006c0885680> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:349)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
Locked ownable synchronizers:
- None ITzhangqiang commented on Jul 21, 2021 so how to slove this issue? Suddenlove commented on Mar 1, 2022 My application changed netty from 3.6.0.Final to 3.10.6.Final and CPU usage returns to normal, JDK version is 1.8.0_101. happyforver commented on Dec 12, 2022
We are still having same issue on Development environment jdk1.8,Operating environment jre 1.2. #27 daemon prio=5 os_prio=0 tid=0x00007f6cc41f3000 nid=0xbc59 runnable [0x00007f6cd69f4000] 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 <0x00000006c08856c8> (a sun.nio.ch.Util$3) - locked <0x00000006c08856d8> (a java.util.Collections$UnmodifiableSet) - locked <0x00000006c0885680> (a sun.nio.ch.EPollSelectorImpl) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97) at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:349) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
Locked ownable synchronizers: - None
Workeryuan
hi, now, i have same issue. do you fix this ? happyforver commented on Dec 13, 2022 i updated to jdk11 , not working...
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|