Problem Statement
Your Go service runs in a 2GB container but keeps getting OOM killed. Configure GOMEMLIMIT and GOGC to prevent this while maintaining performance.
GOGC (Garbage Collection Percentage)
GOMEMLIMIT (Go 1.19+)
Container Configuration
The Old Ballast Technique (Obsolete)
Debugging Memory Issues
Best Practices
- Set GOMEMLIMIT to 80-90% of container memory
- Leave room for OS file cache and overhead
- Monitor with
runtime.ReadMemStats() - Use pprof heap profiles to find allocations