Java · reference

JVM Tuning Concepts

Why is JVM tuning important?

For simple uni-processor based Java applications the JVM default tuning parameters are sufficient as the heap size and processes are limited.
However, for large systems running on multi-processor systems this may not hold true. With large number of objects and huge heap sizes, the garbage collector may run too slow to be effective. This may lead to a precipitious fall in system throughput.

A good analogy will be a person with a vaccum cleaner trying to clean a single room vs trying to clean a large mansion. It will take a lot longer for the person to clean a mansion compared to cleaning a single room.

What are the important concepts of JVM tuning and memory management?

  1. Ergonomics
  2. Generations

Ergonomics

Ergonomics was a feature intoduced in Java 1.5. It’s goal is to provide good performance from JVM with minimum command line tuning.
It tries to create the best selection of three parameters for an application.

  1. Garbage collector
  2. Heap size
  3. Runtime compiler

Generations

Instead of creating all the objects in a single heap, it is more efficient to create them under different memory pools.
These pools are called as generations. There are three main types of pools

  1. Young Generation
  2. Tenured Generation
  3. Permanent Generation(Perm Gen)

All the objects are created in the young generation pool.
Young generation is made up of three parts:

  1. Eden
  2. Survior Space 1
  3. Survior Space 2

When the young generation pool gets filled up the GC (Garbage Collector) finds all the unreferenced objects and deallocates them. This is called as minor collection. Minor collections are very fast and can quickly reclaim a lot of garbage. This is because most of the objects do not survive for a very long time as they are created for methods that don’t last that long. The leftover objects after minor collection are then moved to the survivor space 1 and then survivor space 2.

The bigger the young generation, the less often minor collections occur. HOwever, as we increase YG, the space for TG and PG decrease in the heap.

Once an object is not collected from survivor space 2 after minor GC run, it is moved to the tenured generation pool.
Thus tenured generation pool contains only the longer living objects.

Permanent generation is the that part of the memory which is used to hold the permanent objects. Like the class and method codes for JVM.
This generation holds the meta data about the classes that have been loaded. This area is also garbage collected but at a slower rate.

Performance of Garbage Collection

What are the two main considerations for Garbage Collection?

  1. Throughput
  2. Pauses

What are the four considerations for generation sizes?

  1. Throughput
  2. Footprint
  3. Promptness
  4. Pauses

What is Throughput?

From oracle.com definition :

Throughput is the percentage of total time not spent in garbage collection, considered over long periods of time. Throughput includes time spent in allocation (but tuning for speed of allocation is generally not needed.) Pauses are the times when an application appears unresponsive because garbage collection is occurring.

What is Footprint?

From oracle.com definition :

Footprint is the working set of a process, measured in pages and cache lines. On systems with limited physical memory or many processes, footprint may dictate scalability.

What is Promptness?

From oracle.com definition :

Promptness is the time between when an object becomes dead and when the memory becomes available, an important consideration for distributed systems, including remote method invocation (RMI).

What are pauses?

From oracle.com definition :

Pauses are the times when an application appears unresponsive because garbage collection is occurring.

What are the four types of Garbage Collectors?

  1. Default Collector
  2. Throughput Collector
  3. Concurrent Low Pause Collector
  4. Incremental Low Pause Collector

For more information refer:

Advertisements

One thought on “JVM Tuning Concepts

  1. I had fun reading this post. I want to see more on this subject.. Gives Thanks for writing this nice article.. In Any Case, I’m going to sign to your rss and I wish you write great articles again soon.

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 )

Google+ photo

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

Connecting to %s