Chapter 5. Tuning WebSphere Application Server 93
Example 5-2 on page 92 shows in the highlighted line that the heap size has
been increased to just over 77MB (81674232-bytes) during the startup of
WebSphere Commerce Server JVM process. Therefore, the first thing you need
to consider is increasing the minimum heap size by using -Xms option. You will
need to further examine the output in order to estimate how much the heap size
should be increased. Making the heap size a little bigger than the point where
JVM heap size was automatically increased will be a good starting point. Taking
this into account, we decided to increase the minimum heap size (-Xms) to 85MB
in our tests. It turned out that we could avoid expansion of the heap area with this
size, but it was still not sufficient to avoid garbage collection during startup. So
we then increased the minimum heap size to 96MB. This setting did prevent
expansion as well as garbage collection from occurring.
5.2.2 Monitoring garbage collection
It is normal for garbage collection to consume anywhere from 5% to 20% of the
total execution time of a well-behaved WebSphere application. If not kept in
check, garbage collection can be your applications biggest bottleneck, especially
when running on Symetric MultiProcessor (SMP) server machines.
The problem with garbage collection is simple; during garbage collection, all
application work stops. This is because modern JVMs support a single-threaded
garbage collector. During garbage collection, not only are freed objects collected,
but memory is also compacted to avoid fragmentation. It is this compacting that
forces Java to stop all other activity in the JVM. Figure 5-9 shows how garbage
collection can impact performance on a 2-way SMP computer.
Figure 5-9 JVM garbage collection
94 WCS V5.1 Performance Tuning
To analyze the behavior of garbage collection, you can use a small java program
named GCStats. In order to use it, you must first obtain its source code and
compile the source. We have included the source code of GCStat in Appendix D,
GCStats.java on page 199. GCStats tabulates statistics using the output of the
-verbosegc flag of the JVM. Therefore, you must start WCS server with
-verbosegc option before running GCStats. GCStats takes two arguments. The
first argument is the location of output file contain verbosegc data. The second
argument is the duration of the workload in which garbage collection took place.
It is specified in milliseconds. For example:
java GCStats /usr/lpp/CommerceSuite/instances/myinstance/logs/wcs.log 3600000
This tool summarizes the collected information about garbage collection activity
and is stored in the standard output log file. Example 5-3 below shows a sample
output of GCStats captured during the startup phase of WebSphere Commerce
Server. Minimum heap size was not specified in this case.
Example 5-3 Sample output of GCStats
FreeMem: 705720
TotalMem: 1048567
UsedMem: 343360
-------------------------------------------------
- GC Statistics for file - wcs.log
-------------------------------------------------
-**** Totals ***
- 41 Total number of GCs
- 14098 ms. Total time in GCs
- 523523 Kbytes. Total memory collected during GCs
-
-**** Averages ***
- 343 ms. Average time per GC. (stddev=229 ms.)
- 12768 Kbytes. Average memory collected per GC. (stddev=11450 Kbytes)
- 29%. Free memory after each GC. (stddev=7%)
- 0.4699333333333333% of total time (3000000ms.) spent in GC.
___________________________ Wed May 09 17:04:22 CDT 2001
GCStats can provide clues as to whether your application is over utilizing
objects. The primary statistic to look at is total time spent in GC (the last
statistic presented in the output). As a rule of thumb, this number should not be
much larger than 15%.
If the number leads you to believe that over-utilizing objects is leading to garbage
collection bottleneck, there are two possible actions. The most cost effective but
limited remedy is to optimize your application by implementing object caches and
pools. Use a Java profiler to determine which objects in your application should
be targeted. But this method is applicable only when you have access to source

Get WCS V5.1 Performance Tuning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.