← Workflows

阅读中文版本

Memory Pressure Tuning Workflow

Diagnose memory-related slowdowns and OOM kills by measuring allocation growth, then tuning limits or fixing leaks.

advanced~70 minperformancememoryreliability

Objective

Reduce memory pressure causing slowdowns or OOM kills without guessing at limits.

Environment

  • Runtime memory metrics
  • A profiler for allocations
  • Container memory limits

Steps

1. Measure growth over time

Track memory usage across a sustained workload to distinguish leaks from steady-state usage.

Expected state: You know if memory grows unboundedly or plateaus.

2. Profile allocations

Use an allocation profiler to find the objects responsible for growth.

Expected state: The dominant allocators are identified.

3. Decide leak versus pressure

Fix a genuine leak or raise limits when steady-state usage simply exceeds them.

Expected state: The fix matches the root cause.

4. Verify stability

Confirm memory stays flat and no OOM kills occur under the same load.

Expected state: Memory use is stable under load.

Decision points

Raise limits or fix the leak?

  • Fix leaks, raise limits otherwise
  • Always raise limits

Fix leaks; raise limits only when steady-state usage legitimately needs more.

GC tuning or allocation reduction?

  • Reduce allocations first
  • Tune GC first

Reduce allocations first; tuning GC around a leak only delays the problem.

Expected outcome

Memory issues are resolved by addressing the true cause, whether a leak or an undersized limit.

Verification

Confirm memory plateaus under sustained load and OOM kills stop without masking a leak by raising limits.

Cleanup

Record the new limits and the allocation findings for future diagnosis.

Overview

Reduce memory pressure causing slowdowns or OOM kills without guessing at limits.

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

Environment and prerequisites

  • Runtime memory metrics
  • A profiler for allocations
  • Container memory limits

Procedure

1. Measure growth over time

Track memory usage across a sustained workload to distinguish leaks from steady-state usage.

Expected state: You know if memory grows unboundedly or plateaus.

2. Profile allocations

Use an allocation profiler to find the objects responsible for growth.

Expected state: The dominant allocators are identified.

3. Decide leak versus pressure

Fix a genuine leak or raise limits when steady-state usage simply exceeds them.

Expected state: The fix matches the root cause.

4. Verify stability

Confirm memory stays flat and no OOM kills occur under the same load.

Expected state: Memory use is stable under load.

# watch RSS across a soak
while true; do ps -o rss= -p $(pgrep -f server) ; sleep 30; done

Verification

Confirm memory plateaus under sustained load and OOM kills stop without masking a leak by raising limits.

Decision points

Raise limits or fix the leak?

  • Fix leaks, raise limits otherwise
  • Always raise limits

Recommendation: Fix leaks; raise limits only when steady-state usage legitimately needs more.

GC tuning or allocation reduction?

  • Reduce allocations first
  • Tune GC first

Recommendation: Reduce allocations first; tuning GC around a leak only delays the problem.

Common failures

  • Raising limits masks leaks.
  • GC tuning around leaks delays OOM.
  • No growth measurement leads to wrong fixes.