Skip to main content

Problem Symptoms

Memory leaks and OOM errors usually manifest themselves with the following symptoms:
  • Pods continuously restarting
  • OutOfMemoryError log records
  • Slowly increasing memory usage
  • Decrease in system performance
  • Pods transitioning to OOMKilled state in Kubernetes

Problem Causes

Memory leaks and OOM errors can usually be caused by the following factors:
  • Insufficient Heap Settings: JVM heap size may be insufficient
  • Memory Leaks: Unused objects not being cleaned by garbage collection
  • Large Data Processing: Processing large message bodies
  • Cache Sizes: Cache growing unlimited
  • Connection Pool Issues: Connections not being closed
  • Thread Pool Issues: Threads not being properly cleaned

Detection Methods

1. Log Analysis

Search for OOM errors in log files:

2. Monitoring Memory Metrics

Monitor memory usage with Prometheus metrics:
  • jvm_memory_used_bytes
  • jvm_memory_max_bytes
  • container_memory_usage_bytes

3. Heap Dump Analysis

1

Take Heap Dump

Detect memory leaks by taking heap dump:

Solution Recommendations

1. Optimizing JVM Heap Settings

Set JVM parameters in Pod deployment:
Recommendations:
  • Apinizer’s automatic memory profile selects the appropriate GC and heap percentage based on container memory (Serial GC at ≤768 MB, G1GC at 769-1536 MB, ZGC at >1536 MB)
  • For containers with more than 1536 MB, ZGC is auto-selected with 70% heap — providing sub-millisecond GC pauses
  • If you prefer manual configuration, use G1GC with MaxGCPauseMillis for predictable pause times
  • See JVM Garbage Collector Tuning for detailed GC configuration options

2. Increasing Memory Limits

Increase memory limits in Kubernetes deployment:

3. Optimizing Cache Configuration

Set cache TTL and size limits:
  • Optimize cache TTL values
  • Determine cache size limits
  • Clean unnecessary cache entries

4. Optimizing Connection Pool Settings

Check connection pool settings:
  • Limit maximum connection count
  • Set connection timeout values
  • Regularly clean idle connections

5. Thread Pool Management

Optimize thread pool settings:
  • Limit maximum thread count
  • Set thread timeout values
  • Ensure threads are properly cleaned

6. Optimizing Large Message Processing

When processing large message bodies:
  • Use streaming
  • Determine message size limits
  • Avoid unnecessary data copying

Preventive Measures

1. Regular Monitoring

  • Regularly monitor memory usage
  • Get early warning by setting up alerts
  • Detect problems in advance by performing trend analysis

2. Load Testing

  • Perform regular load tests
  • Detect memory leaks early
  • Perform capacity planning

3. Code Review

  • Review code that may cause memory leaks
  • Check resource management
  • Follow best practices