Garbage Collection Policy Settings

Java garbage collection (GC) is an automatic memory management system that attempts to reclaim memory used by objects that are no longer in use. This page describes StreamBase Systems' suggested starting point for configuring the GC policy for running StreamBase Server.

When you generate a default StreamBase Server configuration file in Studio and you opt to include the default contents, or when you generate a default configuration file with sbd –s, it contains the following settings for the <java-vm> element:

<java-vm>
  <param name="jvm-args" value="
    -XX:+UseParNewGC
    -XX:+UseConcMarkSweepGC
    -XX:+CMSParallelRemarkEnabled "/>
</java-vm>

These lines contain the suggested GC policy settings, which represent a compromise between tuple throughput and minimized latency, leaning more toward minimizing latency.

When StreamBase Server is launched without a configuration file (whether from Studio or with sbd at the command prompt), no GC settings are used.

The GC settings above are used for launching StreamBase Server under the following circumstances:

  • You generate a new configuration file with sbd -s, and leave in place the default settings shown above.

  • You generate a blank configuration file in Studio and edit it to include the GC settings above in your <java-vm> element.

StreamBase Studio honors the jvm-args parameter of the <java-vm> element as long as the server configuration file is at the root of the Studio project and is named sbd.sbconf.

StreamBase bundles also run with the suggested GC settings as long as the bundle is created with the configuration file settings described here.

Suggested Default Settings

The following discussion provides guidelines for using the suggested GC policy settings. The terms young generation and stop-the-world are standard in discussions of garbage collection algorithms, and are beyond the scope of this article to define. Refer to a good overview of garbage collection in Java.

-XX:+UseParNewGC

Uses an improved collection algorithm that takes advantage of multiple processor cores to sweep the young generation. Since this is a stop-the-world phase of garbage collection, performance is improved if the collector uses multiple CPU cores while collecting the young generation.

-XX:+UseConcMarkSweepGC

Enables the Concurrent Mark Sweep (CMS) algorithm to be used for managing the old generation. This algorithm is mostly, but not entirely, concurrent, and can eliminate or reduce the frequency of full stop-the-world collections.

-XX:+CMSParallelRemarkEnabled

Enables multiple parallel threads to participate in the remark phase of the CMS algorithm. Since this is a stop-the-world phase, performance is improved if the collector uses multiple CPU cores while collecting the old generation.

The three settings above change the default JVM to use the commonly accepted best practice GC configuration for latency-sensitive applications running on the Java VM. Oracle has not made these the default settings for Java 6 to preserve backward compatibility, and to prevent any slowdowns in high throughput applications.

Alternate Settings

Your application might benefit from alternate GC settings to tune the server more toward high throughput or more toward low latency.

High Throughput Settings

If your application would benefit from high throughput, then replace all four GC settings described above with a single entry, -XX:+UseParallelGC, as shown in the following example:

<java-vm>
  <param name="jvm-args" value="
    -XX:MaxPermSize=128m
    -Xms256m -Xmx512m
    -XX:+UseParallelGC "/>
</java-vm>

This setting maximizes overall throughput over the course of a business day at the expense of significant garbage collection pauses. The pauses occur less often than with the suggested default settings, but the pauses can be on the order of seconds instead of milliseconds. Do not use this alternative for applications that are latency sensitive.

Low Latency Settings

Settings that minimize latency at the expense of throughput are application-dependent, and cannot be suggested in advance without analyzing your running application. The lowest latency settings tune the size of the various garbage collection generations based on the longevity and survival rates of various Java objects, as determined by low-level profiling of your application running with real-world data.

Contact StreamBase Technical Support for assistance determining very low latency settings for your application.

Settings to Avoid

If you experiment with different GC policy settings, avoid using the following:

-XX:+CMSIncrementalMode

This setting is designed for machines with a small number of low-power processors.

-XX:+UseParallelGC

Do not use this setting at the same time as the recommended alternative, -XX:UseParNewGC.

-XX:+UseAdaptiveSizePolicy

This setting contradicts the recommended -XX:+UseConcMarkSweepGC setting.