Skip to main content

AI & assistant-friendly summary

This section provides structured content for AI assistants and search engines. You can cite or summarize it when referencing this page.

Summary

Heap too small triggers G1 humongous allocations; too large balloons pause times on Graviton. Corretto on ECS/EKS/Lambda Java—when ZGC generational beats G1 for API heaps.

Key Facts

  • Heap too small triggers G1 humongous allocations; too large balloons pause times on Graviton
  • Corretto on ECS/EKS/Lambda Java—when ZGC generational beats G1 for API heaps
  • Amazon Corretto 21+ (June 2026) defaults to G1 on server classpaths; ZGC with generational mode targets sub-ms pauses on large heaps (>8 GB)
  • Enable GC logs to CloudWatch via sidecar or JFR snapshots on load test
  • 2

Entity Definitions

Lambda
Lambda is an AWS service discussed in this article.
CloudWatch
CloudWatch is an AWS service discussed in this article.
EKS
EKS is an AWS service discussed in this article.
ECS
ECS is an AWS service discussed in this article.

JVM G1 and ZGC Tuning on AWS Corretto for ECS and EKS

Quick summary: Heap too small triggers G1 humongous allocations; too large balloons pause times on Graviton. Corretto on ECS/EKS/Lambda Java—when ZGC generational beats G1 for API heaps.

Key Takeaways

  • Heap too small triggers G1 humongous allocations; too large balloons pause times on Graviton
  • Corretto on ECS/EKS/Lambda Java—when ZGC generational beats G1 for API heaps
  • Amazon Corretto 21+ (June 2026) defaults to G1 on server classpaths; ZGC with generational mode targets sub-ms pauses on large heaps (>8 GB)
  • Enable GC logs to CloudWatch via sidecar or JFR snapshots on load test
  • 2
JVM G1 and ZGC Tuning on AWS Corretto for ECS and EKS
Table of Contents

Amazon Corretto 21+ (June 2026) defaults to G1 on server classpaths; ZGC with generational mode targets sub-ms pauses on large heaps (>8 GB).

Symptom → mechanism → AWS control

Production symptomMechanismAWS control
Periodic latency spikesG1 evacuation pauseSwitch to ZGC generational on Corretto 21+
OOM despite free heapMetaspace or direct buffer leakECS/EKS memory limits, CloudWatch Container Insights
GC logs missing in prodNo unified observabilityADOT Java agent → AMP, JFR streaming on EKS

Opinionated take: On Corretto 21+, default new latency-sensitive services to ZGC generational and keep G1 only for throughput-bound batch workloads.

Benchmark pattern (hypothetical workload) — Corretto 21 on ECS Fargate 4vCPU/8GB, G1 default: 180ms GC pause p99; ZGC generational (-XX:+UseZGC): 4ms p99 pause at same heap, 6% higher CPU overhead; throughput-sensitive batch job favors G1.

Tuning signals on AWS

SignalAction
Pause Young highIncrease -Xmx or reduce allocation rate
Humongous objectsObject size > 50% G1 region—fix batch sizes
Container OOM-XX:MaxRAMPercentage=75 on ECS/EKS cgroups

Lambda Java — minimize heap; cold start includes JVM init—consider SnapStart (where supported) or Graal native for latency SLO.

AWS services map

NeedServiceSkip when
Low-latency JVM runtimeCorretto 21 on ECS/EKSSub-millisecond C++ services
GC telemetryAMP + ADOT Java instrumentationBatch jobs with multi-minute pauses acceptable
Heap sizingFargate task memory / EKS limitsLambda with 128MB fixed heap

What to do this week

  1. Enable GC logs to CloudWatch via sidecar or JFR snapshots on load test.
  2. Match container memory limit to heap + native + metaspace headroom.
  3. A/B G1 vs ZGC on same c7g task size with identical load.

More in This Track

Part of the Engineering Guides library (June 2026).

What this guide doesn’t cover

Virtual threads—part 2 of runtime track.

PP
Palaniappan P

AWS Cloud Architect & AI Expert

AWS-certified cloud architect and AI expert with deep expertise in cloud migrations, cost optimization, and generative AI on AWS.

AWS ArchitectureCloud MigrationGenAI on AWSCost OptimizationDevOps

Recommended Reading

Explore All Articles »