I have a Spring API with a heavy use of memory deployed on kubernetes cluster.
I configured the auto scale (HPA) to look at the memory consumption as a scale criterion, and running a load test everything works well at the time of scale up, however at the time of scale down the memory does not go down and consequently the pods created are not removed. If I run the tests again, new pods will be created, but never removed.
Doing an local analysis using visual VM, I believe the problem is correlated to the GC. Locally the GC works correctly during the test, but at the end of the requests it stops running leaving garbage behind, and it only runs again after a long time. So I believe that this garbage left behind is preventing the HPA from scale down.
Does anyone have any tips on what may be causing this effect or something that I can try?
PS. In the profiler I have no indications of any memory leak, and when I run the GC manually, the garbage left is removed
Here are some additional details:
- Java Version: 11
- Spring Version: 2.3
- Kubernetes Version: 1.17
- Docker Image: openjdk:11-jre-slim
- HPA Requests Memory: 1Gi
- HPA Limits Memory: 2Gi
- HPA Memory Utilization Metrics: 80%
- HPA Min Pods: 2
- HPA Max Pods: 8
- JVM OPS: -Xms256m -Xmx1G