Monday 19 August 2013

GC Performance Metrics-49

Learning Objectives
After completing this session, you will be able to:
‰  Describe the important GC Performance Metrics
‰  Identify the types of Garbage Collectors
Important GC Performance Metrics
‰  Throughput:The percentage of total time not spent in garbage collection is
considered over long periods of time.
‰  Pause time:The length of time during which application execution is stopped while
garbage collection is being performed is called the pause time.
‰  Application Requirement:Different applications have different requirements:
‰  Higher throughput is more important for Web application:Pauses during Garbage
Collection may be tolerable, or simply obscured by network latencies.
‰  Shorter pause time is more important to an interactive graphics application
Types of Garbage Collector
The types of Garbage Collector are:
‰  Serial Collector
‰  Parallel Collector
‰  Parallel Compacting Collector
‰  Concurrent Mark-Sweep (CMS) Collector
Serial Collector
‰  Serial Collector is used for most applications that are running on client-style machines,
which do not have low pause time requirement.
‰  Serial Collector is the default for client-style machines in Java SE 5.
‰  Serial Collector can be explicitly requested with XX:+UseSerialGC.
Parallel Collector
‰  Parallel Collector is also known as Throughput Collector.
‰  This is applied for Java applications, which run on machines with a lot of physical
memory and multiple CPUs and do not have low pause time requirement:
‰  Infrequent but potentially long old generation GC can still occur
‰  Examples: Batch applications, billing, payroll, scientific computing, and so on
‰  Parallel Collector can be explicitly requested with XX:+UseParallelGC.
Parallel Compact Collector
‰  Parallel Compact Collector is used for Javaapplications, which run on machines with
a lot of physical memory and multiple CPUs and do have low pause time requirement.
Parallel operations of old generation collection reduces pause time.
‰  Parallel Compact Collector can be explicitly requested with XX:+UseParallelOldGC.
Concurrent Mark Sweep Collector
Concurrent Mark Sweep Collector is used when an application needs shorter pause time and can
afford to share processor resources with GC when application is running
Applications with relatively large set of long-lived data (a large old generation) and run multi-CPU
machines
Example:Web server
Can be explicitly requested with:
‰  -XX:+UseConcMarkSweepGC
‰  -XX:ParallelCMSThreads=<n>
Scheduling of collection handled by GC:
Based on statistics in JVM
Occupancy level of tenured generation:
‰  -XX:CMSTriggerRatio
‰  -XX:CMSInitiatingOccupancyFraction
CMS Collector in Incremental Mode
‰  CMS Collector can be used in a mode in which the concurrent phases are done
incrementally:
‰  Meant to lesson the impact of long concurrent phases by periodically stopping the
concurrent phase to yield back processing to the application
‰  Can be explicitly requested with XX:+CMSIncrementalMode.
Other Incremental CMS Options
Other incremental CMS options are:
‰  -XX:CMSIncrementalDutyCycle=<n%> (default: 50)
‰  -XX:CMSIncrementalDutyCycleMin=<n%> (default: 10)
‰  -XX:+CMSIncrementalPacing (default: true)
DutyCycle of 10 and DutyCycleMin of0 can help certain applications
Tips and Tricks:
Provide some key points on Garbage Collection.
Solution:
‰  It is not possible to force Garbage Collection. Invoking System.gc may start garbage
process.
‰  Circular references do not prevent objects from being garbage collected.
‰  All objects have a finalize() method. It isinherited from the Object class.
‰  finalize() method is used to release system resources other than memory.
‰  finalize() method is called only once for an object. If an exception is thrown in finalize
(), then the object is still eligible for Garbage Collection (at the discretion of gc).
‰  gc keeps track of unreachable objects and garbage-collects them, but an unreachable
object can become reachable again by letting know other objects of its existence from
its finalize() method (when called by gc). This ‘resurrection’ can be done only once,
since finalize() is called only once for an object.
‰  finalize() can be called explicitly, but itdoes not garbage collect the object.
Summary
‰  Java applications can run out of memory.
‰  Islands of objects can be garbage collected, even though they refer to each other.
‰  Request garbage collection with System.gc(); (recommended).
‰  Class Object has a finalize() method.
‰  The finalize() method is guaranteed to run once and only once before the garbage
collector deletes an object.
‰  The garbage collector makes no guarantees, fianlize() may never run.
‰  You can uneligibilize an object for GC from within finalize().
Test Your Understanding
1.State true or false for the following:
a)There is no guarantee on the order in which the objects will be garbage collected
or on the order in which the finalizers are called. Therefore the program should not
make any decisions based on this assumption.

No comments:

Post a Comment