Accelerating Java: Performance Tuning and Garbage Collection

Document Sample
Accelerating Java: Performance Tuning and Garbage Collection Powered By Docstoc
					Accelerating Java: Performance Tuning and Garbage Collection
Java™ For Business

Tuesday, December 8, 2009

Introduction

Achieve faster runtime performance through garbage collection (GC) tuning • GC tuning involves common pattern recognition across various hardware platforms. • There are 3 different garbage collectors: The serial garbage collector, the parallel garbage collector, and the concurrent mark sweep (CMS) garbage collector.

Sun Confidential: Internal Only

2

Tuesday, December 8, 2009

The garbage collectors use a heap layout system

The “Young Generation” is where new objects are allocated. These objects can then be promoted to the old generation. Only the JVM can allocate objects to the permanent generation.
3

Sun Confidential: Internal Only

Tuesday, December 8, 2009

The Ideal Garbage Collector: And Why It Can't Exist

The perfect garbage collector would do the following 3 things well:

• Have low garbage collection overhead • Have low garbage collection pause times • Have good space efficiency

Sun Confidential: Internal Only

4

Tuesday, December 8, 2009

The Ideal Garbage Collector: And Why It Can't Exist

Unfortunately, there are tradeoffs, and you can really only achieve ground in two of the three. Why?

• For the young and old generation, the larger the heap space, the better • Larger spaces mean less frequent garbage collection, lower garbage collection overhead, and a higher likelihood that the objects will become garbage. • Larger spaces also, in most cases, hinder the performance of the garbage collector. • Keep in mind that sometimes the max heap size is dictated by available memory and/or max space the JVM can address.
Sun Confidential: Internal Only
5

Tuesday, December 8, 2009

Young and Old Generation: What's the Difference?

So why the division between young generation and old generation, and what are the roles of each? Here's a quick breakdown:
• The young generation: • Dictates the frequency of minor garbage collections • Dictates how many objects will be reclaimed in the young generation, along with tenuring threshold + survivor space size tuning • The older generation: • Holds the application's steady-state live size • Decreases the major GC frequency as much as possible One key tuning tactic is to maximize the number of objects reclaimed in the young generation. In the process, keep in mind that your application's memory footprint should not exceed the available physical memory.
Sun Confidential: Internal Only
6

Tuesday, December 8, 2009

Sizing Heap Spaces | Commands
Here's a list of commands we'll be using to tune your garbage collector:
Command
-Xmx<size> -Xms<size> -Xmn<size> -XX:PermSize=<size> -XX:MaxPermSize=<size> -XX:NewSize=<size> -XX:MaxNewSize=<size> -XX:NewRatio=<ratio> -XX:SurvivorRatio=<ratio>

Definition
max heap size initial heap size young generation size permanent generation initial size permanent generation max size initial young generation size max young generation size young generation to old generation ratio survivor space to Eden size ratio

Comments
young generation + old generation young generation + old generation

smaller is bigger smaller is bigger

Sun Confidential: Internal Only

7

Tuesday, December 8, 2009

Sizing Heap Spaces | Commands
Here's a list of commands we'll be using to tune your garbage collector:
Command
-XX:InitialSurvivorRatio=<ratio> -XX:SurvivorRatio=<ratio> -XX:TargetSurvivorRatio=<percent> -XX:InitialTenuringThreshold=<threshold> -XX:MaxTenuringThreshold=<threshold> -XX:+AlwaysTenure -XX:+NeverTenure -XX:ParallelGCThreads=<num> -XX:+UseNUMA

Definition
initial survivor ratio Ratio of survivor to eden How much of the survivor space should be filled Initial tenuring threshold Maximum tenuring threshold Forces tenuring all the time Forces to never tenure number of parallel GC threads Splits the young generation into partitions
Sun Confidential: Internal Only

Comments
ergonomics starts with this value, unless you force a value with -XX:SurvivorRatio

Typically leave extra space to deal with “spikes”

Never keep any objects in the survivor spaces Recommended to not use Default value assumes only one JVM per system Each partition “belongs” to a CPU

8

Tuesday, December 8, 2009

Sizing Heap Spaces • Set -Xms to what you think would be your desired heap size. If you have additional memory available, set -Xmx to something larger than -xms in case the application is hit with additional load during runtime or the database grows in size over time. • Applications requiring an emphasis on performance almost always set -XX:PermSize and -XX:MaxPermSize to the same value. Note that growing or shrinking the permanent generation requires a full garbage collector. • Applications with emphasis on performance tend to use -Xmn to size the young generation since it combines the use of XX:NewSize and -XX:MaxNewSize
Sun Confidential: Internal Only
9

Tuesday, December 8, 2009

Tuning the Young Generation | The Eden Size

The Eden size determines the frequency of minor garbage collectors. It also determines which objects will be reclaimed at age 0 since newly-allocated objects in Eden start from age 0 and are incremented per every minor garbage collector. Increasing the size of the Eden will not always affect minor GC times because minor garbage collection times are proportional to the amount of objects they copy (i.e., the live objects), not the young generation size.

Sun Confidential: Internal Only

10

Tuesday, December 8, 2009

Tuning the Young Generation | The Survivor Size

Another important concept is the survivor size. The survivor size is total size of live objects that survive a minor collection. The survivor size ratio determines the size of survivor spaces, the maximum survivor size that can stay in the young generation, and the overflow that gets promoted to old generation, which can overload the old generation. Increasing the size of survivor spaces beyond a necessary minimum reduces Eden size and provokes more frequent minor collections. Large survivor spaces are needed if transient data lives a long time, smaller ones if not. Try to retain as many objects as possible in the survivor spaces so that they can be reclaimed in the young generation. This reduces the promotions into the old generation and uses old garbage collectors less frequently. Also, try not to unnecessarily copy very long-lived objects between the survivors. This causes unnecessary overhead in minor garbage collectors. A good rule of thumb to follow is that it's generally better to allow more copies to occur than promotions.

Sun Confidential: Internal Only

11

Tuesday, December 8, 2009

Tuning the Parallel Garbage Collector
Now that we've tuned the young generation, let's focus on the parallel garbage collector. Here are some tips to follow:
• Try to avoid / decrease the frequency of major garbage collections, as this will produce unwanted latency and pauses. If you use the Parallel GC in low-pause environments, avoid full garbage collection by avoiding / minimizing promotion and try to maximize the heap size to reduce the allocations done by the garbage collector.

• The Parallel Garbage Collector has ergonomics, which help to improve the out-of-the-box GC performance. We recommend doing manual tuning to achieve maximum performance. Set the parallel garbage collector thread number according to the CPU chip architecture and the number of JVMs deployed on the system, processor set, or zone.

• Another technique is to use NUMA (Non-Uniform Memory Access). NUMA allocates new objects into the partition that belongs to the allocating CPU.
Sun Confidential: Internal Only
12

Tuesday, December 8, 2009

Java for Business

Learn more @ http://sun.com/software/javaforbusiness/

6

Tuesday, December 8, 2009


				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:1346
posted:12/8/2009
language:English
pages:13
Description: Get the most out of your Java installation through tuning and garbage collection.
About We're the Java for Business team at Sun Microsystems.