This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes High CPU utilization, J2EE web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "High CPU utilization, J2EE web application" Watch "High CPU utilization, J2EE web application" New topic
Author

High CPU utilization, J2EE web application

Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
My company builds web applications using
IBM's Websphere application server.
Recently, we noticed that the CPU utilization on
our production server would spike from 20% to
99%
It was occurring at random times.
Initially, we did not know what was causing the problem.
First, we checked to see if this was a known problem with
IBM Websphere 3.5.4
We looked to see if there were any IBM "fixpacks" for this
type of thing.
Next, we checked the "known bugs" list for the JVM. We
found nothing relevant.
We installed the Websphere "Resource Analyzer" tool to see
if it would help.
We checked the JVM heap size and memory usage. It seemed normal.
We decided to get a thread dump from the JVM
Here are instructions for obtaining a thread dump:
http://www.weblogic.com/docs51/techsupport/threaddump.html
http://access1.sun.com/technotes/00608.html
http://developer.java.sun.com/developer/technicalArticles/Programming/Stackt
race/
After creating a thread dump, we studied the output. We determined
that one of the threads was caught in an infinite loop.
The thread dump provided a snapshot of the thread's stack trace.
We inspected our application source code.
We found this code inside a method:
for (int i = 0; i < foo.size(); i++)
{
for (int j = 0; j < bar.size(); i++)
{
// code omitted
}
}

The bug is in the inner for loop. The original programmer
incorrectly used "i++" in the inner for loop.
This prevented the inner for loop from exiting.

After fixing this bug, the high CPU utilization
disappeared.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What was inside the for loop? I assume the eternal loop didn't block your response/output (this was running in a separate thread)?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by Sean Sullivan:
My company builds web applications using
IBM's Websphere application server.
Recently, we noticed that the CPU utilization on
our production server would spike from 20% to
99%
It was occurring at random times.
Initially, we did not know what was causing the problem.
First, we checked to see if this was a known problem with
IBM Websphere 3.5.4
We looked to see if there were any IBM "fixpacks" for this
type of thing.
Next, we checked the "known bugs" list for the JVM. We
found nothing relevant.
We installed the Websphere "Resource Analyzer" tool to see
if it would help.
We checked the JVM heap size and memory usage. It seemed normal.
We decided to get a thread dump from the JVM
Here are instructions for obtaining a thread dump:
http://www.weblogic.com/docs51/techsupport/threaddump.html
http://access1.sun.com/technotes/00608.html
http://developer.java.sun.com/developer/technicalArticles/Programming/Stackt
race/
After creating a thread dump, we studied the output. We determined
that one of the threads was caught in an infinite loop.
The thread dump provided a snapshot of the thread's stack trace.
We inspected our application source code.
We found this code inside a method:
for (int i = 0; i < foo.size(); i++)
{
for (int j = 0; j < bar.size(); i++)
{
// code omitted
}
}

The bug is in the inner for loop. The original programmer
incorrectly used "i++" in the inner for loop.
This prevented the inner for loop from exiting.

After fixing this bug, the high CPU utilization
disappeared.


Was there a question here? Or are we now using this forum to highlight typos of fellow employees?


James Carman, President<br />Carman Consulting, Inc.
pjoisha
Ranch Hand

Joined: Mar 06, 2001
Posts: 123
Those articles were very helpful. Also, thx for sharing your tip ...we use WebSphere 4.x out here and I'm sure ur tip will come in handy.
Thx,
PJ
[ October 03, 2002: Message edited by: Prashanth Joisha ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: High CPU utilization, J2EE web application