Sunday, January 8, 2012

Common bottlenecks in J2EE applications

Enterprise applications written in the Java language involve complex object relationships and utilize
large numbers of objects. Although, the Java language automatically manages memory associated
with object life cycles, understanding the application usage patterns for objects is important. In
particular, verify the following:

• The application is not over-utilizing objects
• The application is not leaking objects
• The Java heap parameters are set properly to handle a given object usage pattern

The garbage collection bottleneck
Examining Java garbage collection gives insight to how the application is utilizing memory.

The garbage collection gauge
You can use garbage collection to evaluate application performance health. By monitoring garbage
collection during the execution of a fixed workload, you gain insight as to whether the application is
over-utilizing objects. Garbage collection can even detect the presence of memory leaks.

Detecting over-utilization of objects
You can check if the application is overusing objects, by observing the counters for the JVM runtime.
By increasing the heap size, you can reduce the number of garbage collection cycles and thereby
reduce the total cost of GC.
If you can not optimize the application, increasing the size of your Java heap may help.

Detecting memory leaks
Memory leaks are more damaging than memory overuse, because a memory leak ultimately leads to
system instability. Over time, garbage collection occurs more frequently until the heap is exhausted
If the free heap continuously declines over time, this may indicate a memory leak.

Memory Leak Testing
The goal of memory leak testing is to magnify numbers.

• Long-running test
Memory leak problems can manifest only after a period of time, therefore, memory leaks are
found easily during long-running tests.

• Repetitive test
In many cases, memory leak problems occur by successive repetitions of the same test case.
The goal of memory leak testing is to establish a big gap between unusable memory and used
memory in terms of their relative sizes.

• Concurrency test
Some memory leak problems can occur only when there are several threads running in the
application. Unfortunately, synchronization points are very susceptible to memory leaks
because of the added complication in the program logic. Careless programming can lead to
kept or unreleased references. The incident of memory leaks is often facilitated or accelerated
by increased concurrency in the system. The most common way to increase concurrency is to
increase the number of clients in the test bed

Java heap parameters
The Java heap parameters also influence the behavior of garbage collection. Increasing the
heap size supports more object creation. Because a large heap takes longer to fill, the
application runs longer before a garbage collection occurs.

Compare the following statistics:
• Number of garbage collection calls.
• Average duration of a single garbage collection call.
• Ratio between the length of a single garbage collection call and the average time between
calls. This can be viewed as the percentage of time spent doing GC processing.
• System paging activity.

Formula to calculate server throughput

. Server Thruput = # of real simultaneous users / ( Average Response Time + Think Time )