Development Etc.

“Maybe it’s about time I expanded the realm of possibilities around here.” – MacGyver

Troubleshooting Hung Systems: Spiked CPU

First off I wanted to thank Filip Hanik. He illustrated this technique in a presentation at SpringOne this year in New Orleans. I happened to actually give a similar presentation to my fellow engineers at my current employer.

The goal here is to figure out using the top command in linux combined with thread dumps to figure out which thread and java code is consuming CPU resources. Below is a step by step walk through on how to accomplish this.

Step 1

Execute top command to determine the process id (PID) for the JBoss server. It will be listed under “java”

Add an Image

Step 2

Run the top command to show only the threads associated with the java process.
Execute top –H –p PID
(In this example the PID is 10937)

Add an Image

Add an Image

Step 3

Execute kill -3
to obtain a stack trace (In this example the PID is 10937)
Note: You can also utilize the dump stack capability in the JBoss JMX Console under the ServerInfo MBean

Add an Image

Step 4

Take the PID of the thread you want to correlate and convert it to hex using calc on Windows.
Add an Image

Add an Image

Step 5

Open the log file and do a search for the hex representation (native ID) of the thread ID. In this example it will be “2ae1

Add an Image

This effectively tells you the line of code that is responsible for consuming the CPU resources.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.