← Workflows

阅读中文版本

GC Pause Tuning Workflow

Reduce garbage collection pauses by finding allocation hotspots first, then tuning collector settings as a second step.

advanced~70 minperformancegcruntime

Objective

Reduce GC pause time by fixing allocation patterns before tuning collector flags.

Environment

  • GC logging
  • An allocation profiler
  • A representative load test

Steps

1. Quantify the pauses

Collect GC logs and quantify pause frequency and duration under load.

Expected state: The pause problem is measured.

2. Find allocation hotspots

Profile allocations to find the code creating most garbage.

Expected state: The main allocation sources are known.

3. Reduce allocations

Fix the hotspots by reusing buffers or avoiding needless object creation.

Expected state: Allocation rate drops measurably.

4. Tune the collector

Adjust heap and collector settings only after allocation fixes, then verify.

Expected state: Pauses fall and throughput holds.

Decision points

Tune flags or fix allocations?

  • Fix allocations first
  • Tune flags first

Fix allocations first; tuning around high garbage only hides the cause.

Bigger heap or better collection?

  • Match heap to live set
  • Maximise heap

Size the heap to the live set; an oversized heap increases pause length.

Expected outcome

GC pauses are reduced by addressing allocation pressure first and tuning the collector second.

Verification

Confirm pause p99 falls and throughput holds, with allocation rate reduced by the code fixes.

Cleanup

Record the settings and allocation findings for future tuning.

Overview

Reduce GC pause time by fixing allocation patterns before tuning collector flags.

This workflow is reusable across teams and environments; adapt the commands to your tooling while keeping the sequence and checkpoints intact.

Environment and prerequisites

  • GC logging
  • An allocation profiler
  • A representative load test

Procedure

1. Quantify the pauses

Collect GC logs and quantify pause frequency and duration under load.

Expected state: The pause problem is measured.

2. Find allocation hotspots

Profile allocations to find the code creating most garbage.

Expected state: The main allocation sources are known.

3. Reduce allocations

Fix the hotspots by reusing buffers or avoiding needless object creation.

Expected state: Allocation rate drops measurably.

4. Tune the collector

Adjust heap and collector settings only after allocation fixes, then verify.

Expected state: Pauses fall and throughput holds.

# analyse GC pause distribution
jq -r 'select(.gcId) | .pause' gc.log | sort -n | tail -20

Verification

Confirm pause p99 falls and throughput holds, with allocation rate reduced by the code fixes.

Decision points

Tune flags or fix allocations?

  • Fix allocations first
  • Tune flags first

Recommendation: Fix allocations first; tuning around high garbage only hides the cause.

Bigger heap or better collection?

  • Match heap to live set
  • Maximise heap

Recommendation: Size the heap to the live set; an oversized heap increases pause length.

Common failures

  • Tuning flags while allocation churns high wastes effort.
  • Oversized heaps lengthen pauses.
  • No GC logs means guessing at pauses.