Java Reference
In-Depth Information
output, rather than eyeballing a GUI graph and guessing what it means. The output can al-
ways be graphed later when doing analysis.
CPU Usage
Let's look first at monitoring the CPU and what it tells us about Java programs. CPU usage is
typically divided into two categories: user time and system time (Windows refers to this as
privileged time). User time is the percentage of time the CPU is executing application code,
while system time is the percentage of time the CPU is executing kernel code. System time is
related to the application; if the application performs I/O, for example, the kernel will ex-
ecute the code to read the file from disk, or write the buffered data to the network, and so on.
Anything that uses an underlying system resource will cause the application to use more sys-
tem time.
The goal in performance is to drive CPU usage as high as possible for as short a time as pos-
sible. That may sound a little counterintuitive; you've doubtless sat at your desktop and
watched it struggle because the CPU is 100% utilized. So let's consider what the CPU usage
actually tells us.
The first thing to keep in mind is that the CPU usage number is an average over an inter-
val—5 seconds, 30 seconds, perhaps even as little as 1 second (though never really less than
that). Say that the average CPU usage of a program is 50% for the 10 minutes it takes to ex-
ecute. If the code is tuned such that the CPU usage goes to 100%, the performance of the
program will double: it will run in 5 minutes. If performance is doubled again, the CPU will
still be at 100% during the 2.5 minutes it takes the program to complete. The CPU number is
an indication of how effectively the program is using the CPU, and so the higher the number
the better.
If I run vmstat 1 on my Linux desktop, I will get a series of lines (one every second) that
look like this:
% vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 1797836 1229068 1508276 0 0 0 9 2250 3634 41 3 55 0
2 0 0 1801772 1229076 1508284 0 0 0 8 2304 3683 43 3 54 0
1 0 0 1813552 1229084 1508284 0 0 3 22 2354 3896 42 3 55 0
1 0 0 1819628 1229092 1508292 0 0 0 84 2418 3998 43 2 55 0
Search WWH ::

Custom Search