Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

High CPU utilization, J2EE web application

 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was inside the for loop? I assume the eternal loop didn't block your response/output (this was running in a separate thread)?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
pjoisha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic