I have a Java Application (web-based) that at times shows very high CPU Utilization (almost 90%) for several hours. Linux TOP
command shows this. On application restart, the problem goes away.
So to investigate:
I take Thread Dump to find what threads are doing. Several Threads are found in 'RUNNABLE'
state, some in few other states. On taking repeated Thread Dumps, i do see some threads that are always present in 'RUNNABLE'
state. So, they appear to be the culprit.
But I am unable to tell for sure, which Thread is hogging the CPU or has gone into a infinite loop (thereby causing high CPU util).
Logs don't necessarily help, as the offending code may not be logging anything.
How do I investigate - What part of the application or what-thread is causing High CPU Utilization? - Any other ideas?
Peripheral causes of high Java CPU usagebad JVM memory management; poorly configured Java GC; issues more correctly attributable to the software stack; thread synchronization, contention and deadlock issues; and.
You can expect high CPU utilization when playing some games, running a video-editing or streaming application, performing an antivirus scan, or juggling many browser tabs.
You can set the priority of your whole Java application process to be lower than other applications; that's what the "nice" or "renice" commands do for your on Unix (or Mac OS X). Alternatively, and I think nicer, you can start a reduced-priority thread within your application, to do the CPU-intensive work.
If a profiler is not applicable in your setup, you may try to identify the thread following steps in this post.
Basically, there are three steps:
top -H
and get PID of the thread with highest CPU.You may be victim of a garbage collection problem.
When your application requires memory and it's getting low on what it's configured to use the garbage collector will run often which consume a lot of CPU cycles. If it can't collect anything your memory will stay low so it will be run again and again. When you redeploy your application the memory is cleared and the garbage collection won't happen more than required so the CPU utilization stays low until it's full again.
You should check that there is no possible memory leak in your application and that it's well configured for memory (check the -Xmx
parameter, see What does Java option -Xmx stand for?)
Also, what are you using as web framework? JSF relies a lot on sessions and consumes a lot of memory, consider being stateless at most!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With