Using JVM Diagnostics (JVMD) to help tune production JVMs
By Shiraz Kanga-Oracle
Tuning Heap Size
[g|m|k] is the initial and minimum size of the Java heap
[g|m|k] is the maximum possible size that the Java heap can grow upto
- The throughput of a JVM is measured in terms of the time spent doing garbage collection vs. the time spent outside of garbage collection (referred to as application time). It is the inverse of GC overhead mentioned above and represents the amount of work done by an application as a ratio of time spent in GC. Throughput can be tuned with -XX:GCTimeRatio=99 where 99 is the default which represents a 1% GC overhead.
- Latency is the amount of time delay that is caused by garbage collection. Latency for GC pauses can be tuned by specifying rhe maximum pause time goal with the command line option -XX:MaxGCPauseMillis=
. This is interpreted as a hint that pause times of milliseconds or less are desired. By default, there is no maximum pause time goal. If a pause time goal is specified, the heap size and other garbage collection related parameters are adjusted in an attempt to keep garbage collection pauses shorter than the specified value. Note that these adjustments may cause the garbage collector to reduce the overall throughput of the application and in some cases the desired pause time goal cannot be met.
[g|m|k] is the initial and minimum size of the permanent generation space.
[g|m|k] is the maximum size of the permanent generation space. If you ever get the message java.lang.OutOfMemoryError: PermGen space then it means that your application is loading a very large number of classes and this should be raised.
[g|m|k]is the size of the thread stack.Each thread in a Java application has its own stack. The stack is used to hold return addresses, arguments to functions and method calls, and so on. The default stack size setting for a thread in Java is 1MB. In a highly multi-threaded system, like an application server at any given point in time there are multiple thread pools and threads that are in use so this may need to be reduced. Since stack size has to be allocated in contiguous blocks and if the machine is being used actively and there are many threads running in the system you may encounter an OutOfMemory error even when you have sufficient heap space. Recursive code can quickly exhaust the stack and if you use such code then you may need to increase the -Xss setting. However, if you see java.lang.OutOfMemoryError: unable to create new native thread then you may have too many threads, or each thread has a large stack; so you may need to decrease it.
Tuning Garbage Collection Algorithm
- Eden space: All objects are placed here when first created
- Survivor spaces: One or more regions where objects mature
- Tenured space: Where long lived objects are stored
- Permanent generation: This area is only used by the JVM itself to hold metadata, such as data structures for classes, methods, interned strings
- -XX:+UseSerialGC uses a single threaded, young generation, and old generation garbage collector (Normally this is a poor choice and should be used only for small Java heap sizes such as -Xmx256m or smaller)
- -XX:+UseParallelGC utilizes a multithreaded (parallel) garbage collector for the young generation and a single-threaded garbage collector for the old generation space in parallel.
- -XX:+UseParallelOldGC uses a multithread garbage collector for both the young and old generations.
- -XX:+UseParNewGC -> enables a multithreaded, young generation garbage collector
- -XX:+UseConcMarkSweepGC -> enables the VM’s mostly concurrent garbage collector. It also auto-enables -XX:+UseParNewGC (use if If you are not able to meet your application’s worst case latency requirements due to full garbage collection duration being too long)
- -XX:+UseG1GC -> garbage first collector (default in java 7, can be also used in latest releases of Java 6)