Reason for aggresive CPU utilization by application server
We are running a JAVA application in JBOSS with oracle.We have used Seam and H开发者_JAVA百科ibernate frameworks.The problem we are facing is,when we start tha application server the cpu utlizations increase and after one hour we found that CPU utilizaiton is close to 90%.It is bizarred and I am not able to identify the problem.
Please Help.Thanks in Advance.
Cheers, Dwarak
Ideally you can use a profiler to track down the problem. If you can't use a profiler in the environment it's in (like production) then try to reproduce it somewhere else and attach a profiler there. Often that can be difficult though, so here's a trick I've used a number of times to find the cause of CPU utilization in production from the command line:
watch -n1 'jstack [pid] | grep -A 1 RUNNABLE | grep -v RUNNABLE | grep -v \\-\\- | grep -v socketRead0 | grep -v socketAccept`
If you watch this for a short period of time you might see some common methods being called. Next grab a full jstack output to a file:
jstack [pid] > jstack.log
Now search the file for one of the methods that you saw showing up frequently. From its stack trace you can usually find the code responsible for grinding the CPU. If nothing shows up then perhaps your time is going to excessive garbage collection and you simply need to increase memory. You can use:
`jmap -heap [pid]`
To get a better idea of memory usage. Better yet you can attach jvisualvm or a commercial profiler (like YourKit) to see it graphically over time. I've also used watch -n1 'jmap -heap [pid]'
on occasion.
- First off, make sure that it's the process which is executed by JBoss which hogs up the CPU. If you are using Linux use top command, or in Windows, use Task Manager to monitor the CPU utilization by java process which runs JBoss.
- If that is the case, take a look at your server log files to see what happens during this time. Is it really doing some significant work, or is the CPU utilization is high when your application is idling also ?
- Make sure that you have enough free memory in the system for OS. If the jboss process eats up all the free memory, the OS will not have enough memory for it's own activities, which could lead up to thrashing (swapping pages in and out of virtual memory which eats up CPU).
- Make sure you have given adequate heap memory to JVM. You can increase these values in run.conf file in the bin directory of JBoss. When the heap size is too small for your application, thrashing can occur. Also, if the heap size is too large (over 2GB for example), then the time taken to GC the heap will also hog up your CPU.
- Check Disk I/O on your machine when JBoss runs. If you set your log levels to very low values, and if JBoss ends up writing massive log files, that could also lead to high CPU usage (for writing log files !).
- If you are using JDK 1.5.0.10, take a look at this link. My JBoss server hits 100% SYS CPU on Linux; what can cause this?
If nothing above helps, the last resort is to go for a profiling tool. I suggest JProfiler or Yourkit Profiler (Commercial, but 30-day trail available) which is very user-friendly.
Use a profiler to find the problem. If using Oracle Java 6, start with jvisualvm in the JDK.
精彩评论