Child pages
  • Tuning the JVM

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Caveat: These are recommendations only and it is recommended that customers refer to Oracle and other tuning documentation, and use a performance testing optimisation strategy to optimally configure IG according to deployment. Only an incremental optimisation strategy will determine the optimal configuration for a given deployment and user load.


Info
titleSummary

Before tuning the JVM, be sure to understand and define performance targets, and select an appropriate JVM and garbage collector (GC).

Memory

As a proxy, IG is generally a low memory consumer, proxying request and response data between the client and server. Other factors to consider though in determining memory sizes are:

...

OptionDescription
-serverEnsures the JVM uses server-optimised configuration, compilation and execution. This is the default with a 64-bit JVM.

-XX:InitialHeapSize<size>G

-XX:MaximumHeapSize=<size>G

Configure the initial and maximum heap space:

  • Equivalent to -Xms and -Xmx flags respectively.
  • Oracle recommend that these figures are set the same to avoid expensive allocation operations. However, recent improvements in G1GC with its adaptive optimization algorithm (see below) means that this may limit vertical scaling. Though it is still recommended to follow this practice, if using G1GC, consider testing individual initial and maximum values too.
  • As a start point, IG has been shown to operate well in performance testing with a heap size of 5Gb. That is, with this sized heap, even with more memory available, a memory increment was never done.

-XX:NewSize=<size>G

-XX:MaxNewSize=<size>G

Configure the initial and maximum YoungGen space:

  • This configuration is important to IG as a large consumer of Eden space.
  • Incrementally test to optimise, with anticipated concurrent load in a pre-production environment. The maximum should be within the overall allocated maximum heap-size (-Xmx), leaving space for non-heap memory.
  • If using G1GC, it is advised not to set these values and instead allow G1GC to optimise based on use. As ever, this should be tested.

-XX:+UseStringDeduplication

-XX:UseStringDeduplicationAgeThreshold=<N>

Prevent String duplication and so conserve memory (java 8u20+), reducing GC needs. The threshold can be provided to specify the age after which a String becomes a candidate for deduplication.

Note

GSA: why not, but do we think that this can have a notable impact on our performances ?

WM: It's documented everywhere as advisable. It's also advised in the DJ tuning guide for 7.0. It's basically the inlining of Strings, as used to be the case pre-java8.

(Will remove Tuesday 30/6/2020 if no further comment)

-XX:MaxTenuringThreshold=<N>

Configure the number of transitions between survivor spaces before an object is moved to OldGen.

Because IG largely consumes YoungGen space, we can determine that anything that eventually would live in OldGen space could be moved there early to free up Eden space and reduce objects transitioning between survivor spaces. We could therefore set -MaxTenuringThreshold to a low value, possibly as low as 1 to accomplish this.

Note

GSA: Good, this is exactly the kind of description that is useful to our users: it explains why this is worth considering this option

WM: Thanks

(Will remove Tuesday 30/6/2020 if no further comment)

-XX:MetaspaceSize=<size>G

-XX:MaxMetaSpaceSize=<size>G

Configure initial and maximum Metaspace size (from java 8). IG 

Note

GSA: Unsure if we should keep this one in the doc, for sure not in the first positions, it's relatively less important than young/old gen settings

WM: Probably not vital but it is included in other guides and I think it's important to note we only need a smallish Metaspace. I've moved it to last position, as I want to describe it as II've provided a recommended default

(Will remove Tuesday 30/6/2020 if no further comment)

Info
titleSummary

IG makes low memory demands and specifically is mostly a consumer of YoungGen  memory. Use of caches or proxying of large resources will increase OldGen  memory use.

The specific settings described in this section may be considered when optimising JVM memory. See Oracle documentation for more information.

Garbage collection (GC)

Selecting the right garbage collector and tuning collection can reduce expensive "stop the world" pauses in collection. As IG is largely a consumer of YoungGen memory, there is a lot of scope for tuning to avoid expensive major collections (OldGen space consumption).

...

Code Block
languagebash
titleUseful G1GC configuration options
-XX:InitialHeapSize=5g -XX:MaxHeapSize=5g \
-XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M \
-XX:MaxTenuringThreshold=1 \
-XX:+UseStringDeduplication \
-XX:+UseG1GC \
-XX:MaxGCPauseMillis=500\
Info
titleSummary

Care should be taken in selecting an appropriate garbage collector, depending on your identified performance targets.

G1 is designed for multiprocessor environments with large available memory with the intent of good overall performance without the need to specify additional options. It is designed to reduce garbage collection through low-GC latency. It is largely self-tuning, with an adaptive optimisation algorithm, but there are a number of options to consider to suite the needs of the protected web application. See Oracle G1 collector documentations and tuning guide.

The Parallel GC aims to improve garbage collection by following a high-throughput strategy, but requires more full GCs. See Oracle Parallel GC documentation.

Generally, the recent addition of the G1 garbage collector is largely promoted by Oracle to satisfy most needs, but testing should be done to compare the results of G1 and the Parallel collector in typical business use cases.

References

  1. KB FAQ: IG Performance and Tuning
  2. KB BestPractice: Best practice for JVM Tuning (java 7)
  3. KB HowTo: How do I collect JVM data for troubleshooting IG/OpenIG (All versions)?
  4. KB HowTo: How do I enable Garbage Collector (GC) Logging for IG/OpenIG (All versions)?
  5. DZone: Choosing the Right GC
  6. Oracle Parallel Garbage Collector
  7. Oracle Garbage Collection Tuning Guide
  8. Oracle G1GC Tuning Guide
  9. JVM Tuning with G1GC by @marknienaber on medium.com (our very own Mark Nienaber (S))
  10. Improving G1 Out-of-the-box Performance by Stefan Joansson
  11. High Performance at Low Cost – Choose the Best JVM and the Best Garbage Collector for your Needs by Jonatan Kazmierczak
  12. A Step-by-step Guide to Java Garbage Collection Tuning by Rafal Kuc
  13. Reduce Long GC Pauses by gceasy.io

...