Skip to content

Commit

Permalink
Increase G1 default pause target from 200ms to 500ms (#1505)
Browse files Browse the repository at this point in the history
Increase G1 default pause target from 200ms to 500ms
  • Loading branch information
carterkozak authored Aug 1, 2023
1 parent d5b4e0d commit ecfb4ca
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
13 changes: 13 additions & 0 deletions changelog/@unreleased/pr-1505.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: improvement
improvement:
description: |-
Increase G1 default pause target from 200ms to 500ms
The G1 pause target can be modified thusly:
```groovy
gc 'hybrid', {
maxGCPauseMillis 250
}
```
links:
- https://github.com/palantir/sls-packaging/pull/1505
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,24 @@ public final void newRatio(int newerRatio) {
}
}

// Match the MaxGCPauseMillis case
@SuppressWarnings("AbbreviationAsWordInName")
class Hybrid implements GcProfile {
// We use 500ms by default, up from the JDK default value of 200ms. Using G1, eden space is dynamically
// chosen based on the amount of memory which can be collected within the pause time target.
// Higher pause target values allow for more eden space, resulting in more stable old generation
// in high-garbage or low-gc-thread scenarios. In the happy case, increasing the pause target increases
// both throughput and latency. In degenerate cases, a low target can cause the garbage collector to
// thrash and reduce throughput while increasing latency.
private int maxGCPauseMillis = 500;

@Override
public final List<String> gcJvmOpts(JavaVersion _javaVersion) {
return ImmutableList.of("-XX:+UseG1GC", "-XX:+UseNUMA");
return ImmutableList.of("-XX:+UseG1GC", "-XX:+UseNUMA", "-XX:MaxGCPauseMillis=" + maxGCPauseMillis);
}

public final void maxGCPauseMillis(int value) {
this.maxGCPauseMillis = value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
!new File(projectDir, 'dist/service-name-0.0.1/service/lib/com/test/Test.class').exists()
}

def 'adds gc profile jvm settings'() {
def 'adds initiatingOccupancyFraction gc profile jvm settings'() {
given:
buildFile << '''
plugins {
Expand Down Expand Up @@ -1057,6 +1057,41 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
actualStaticConfig.jvmOpts.containsAll(['-XX:+UseParNewGC', '-XX:+UseConcMarkSweepGC', '-XX:CMSInitiatingOccupancyFraction=75'])
}

def 'adds maxGCPauseMillis gc profile jvm settings'() {
given:
buildFile << '''
plugins {
id 'java'
id 'com.palantir.sls-java-service-distribution'
}
repositories {
jcenter()
mavenCentral()
}
version '0.0.1'
distribution {
serviceName 'service-name'
mainClass 'test.Test'
gc 'hybrid', {
maxGCPauseMillis 1234
}
}
'''.stripIndent()

createUntarTask(buildFile)

when:
runTasks(':untar')

then:
def actualStaticConfig = OBJECT_MAPPER.readValue(
file('dist/service-name-0.0.1/service/bin/launcher-static.yml'), LaunchConfig.LaunchConfigInfo)
actualStaticConfig.jvmOpts.containsAll(['-XX:+UseG1GC', '-XX:+UseNUMA', '-XX:MaxGCPauseMillis=1234'])
}

def 'gc profile null configuration closure'() {
given:
buildFile << '''
Expand Down Expand Up @@ -1087,7 +1122,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
then:
def actualStaticConfig = OBJECT_MAPPER.readValue(
file('dist/service-name-0.0.1/service/bin/launcher-static.yml'), LaunchConfig.LaunchConfigInfo)
actualStaticConfig.jvmOpts.containsAll(['-XX:+UseG1GC', '-XX:+UseNUMA'])
actualStaticConfig.jvmOpts.containsAll(['-XX:+UseG1GC', '-XX:+UseNUMA', "-XX:MaxGCPauseMillis=500"])
}

def 'applies java agents'() {
Expand Down

0 comments on commit ecfb4ca

Please sign in to comment.