Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Tuning garbage collection in the HotSpot JVM

Packing 100 megabytes of garbage into a 50 megabyte bag.

Tutorial Details:

With the increase in the popularity of blogs as a public diary, blogging hosts have been growing by leaps and bounds. So to the folks at Blog-City, it was clear that their site needed to evolve and grow. To address its growing needs, the company had just recently rolled out Blog-City version 2.0. As if often the case when a new application is rolled out into production, its performance does not quite meet expectations due to a number of factors, not the least of which was the sudden and seemingly random appearance of long periods of time when the application appeared to be hung.

At its core, Blog-City relies on the Blue Dragon Servlet engine (a CFML engine) and a database. Amazingly, all of this software was hosted on a fairly old P3 running Red Hat Linux. The machine, sporting a single hard disk and 512 MB of RAM, though powerful enough for past loads, was struggling to keep up with the growing load. Blog-City had become a victim of it\'s own success. Even so, this was all the hardware that was going to be available for some time.

Defining the problem
The first step in the process was to determine the cause of the sudden application slowdowns. First on our list of suspects was garbage collection. As we demonstrated in last month\'s column, the easiest way to determine if garbage collection and memory utilization issues are having a negative effect on your applications performance is to set the -verbose:gc JVM option and examine the log output. So we restarted the application with verbose garbage collection logging turned in, and patiently waited for the application\'s performance to fall off. Our patience paid off in the form of a very revealing gc log file.

From the initial analysis of the log files, it was apparent that garbage collection was the bottleneck in this application. This was evidenced by the frequency, duration, and overall efficiency of GC. A common reason for a higher than normal GC frequency is that the heap is barely large enough to accommodate all of the live objects that are currently in use and not quite large enough to accommodate the new ones that are being created. Though there are many reasons why an application may be consuming the amount of heap that it does, not having enough memory causes the garbage collector to thrash as it tries to satisfy the current need. In other words, the application will attempt to allocate a new object and fail, and upon failing, will trigger a garbage collection. If that GC fails to recover enough memory, it will force another, more expensive GC to occur. Even if GC does recover enough space to satisfy the immediate request, you can be sure that it won\'t be very long before the application experiences yet another allocation failure, triggering yet another GC. As a result, instead of the JVM servicing your application, it will focus it attention on the fruitless task of repeatedly scavenging for free heap space.

Though there may be many reasons why an application is consuming all of the available heap space, the expedient solution is to configure a larger heap, if more memory is available. Assuming that the application does not have a memory leak (or what we like to call unintentionally retained objects), it will find a \"natural\" level of heap consumption, which the GC will be able to comfortably maintain (unless the rate of object creation is so high that GC is always in a race to keep up). In this case, and the case of unintentionally retained objects, we will need to make changes to the application in order to obtain any improvement.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Tuning garbage collection in the HotSpot JVM

View Tutorial:
Tuning garbage collection in the HotSpot JVM

Related Tutorials:

The Java HotSpot Performance Engine is set to break new records - JavaWorld
The Java HotSpot Performance Engine is set to break new records - JavaWorld
 
Java memory management
Java memory management
 
Smart object-management saves the day - JavaWorld November 1999
Smart object-management saves the day - JavaWorld November 1999
 
Java performance programming, Part 2: The cost of casting - JavaWorld December 1999
Java performance programming, Part 2: The cost of casting - JavaWorld December 1999
 
Cleaning up after Jini services - JavaWorld March 2000
Cleaning up after Jini services - JavaWorld March 2000
 
Use the JVM Profiler Interface for accurate timing - JavaWorld
Use the JVM Profiler Interface for accurate timing - JavaWorld
 
Optimize a query on a Map - JavaWorld November 2000
Optimize a query on a Map - JavaWorld November 2000
 
Performance books put to the test - JavaWorld March 2001
Performance books put to the test - JavaWorld March 2001
 
J2EE project dangers! - JavaWorld March 2001
J2EE project dangers! - JavaWorld March 2001
 
Accelerate your RMI programming
Accelerate your RMI programming
 
Pick up performance with generational garbage collection
Pick up performance with generational garbage collection
 
Java Tip 130: Do you know your data size?
Java Tip 130: Do you know your data size?
 
J2SE 1.4.1 boosts garbage collection
J2SE 1.4.1 boosts garbage collection
 
Into the mist of serializaton myths
Into the mist of serializaton myths
 
Does an object exist if you can't test its identity?
Does an object exist if you can't test its identity?
 
Tuning garbage collection in the HotSpot JVM
Packing 100 megabytes of garbage into a 50 megabyte bag.
 
A Collection of JVM Options
This document is a compilation of all the JVM options for various versions of the JVM on primarily SPARC/Solaris Platform. The descriptions for each option are taken mostly verbatim from the reference documents.
 
Garbage Collection in the Java HotSpot Virtual Machine
Garbage Collection in the Java HotSpot Virtual Machine Gain a better understanding of how garbage collection in the Java HotSpot VM works, and learn to take full advantage of it when designing, developing, and deploying your Java applications.
 
Core Java Interview Questions!
Core Java Interview Questions! Core Java Interview Questions Question: What is transient variable? Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written
 
New Technical Articles: 64-bit Programming on Solaris 10 OS for x86 Platforms
Four technical articles describe the new Sun Studio 10 software's 64-bit programming features on the Solaris 10 OS for x86 and AMD64 platforms. Important issues regarding the AMD64 ABI (Application Binary Interface), debugging, migration to 64-bits, and p
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.