spring batch: AKS container is not releasing the Memory after the job execution

Viewed 289

I am running the spring batch application in AKS container. I see that it is not releasing the Memory after the spring batch job execution.

it is holding almost 1.4Gi post job execution

I am using the below command to run the spring batch job

java -jar jarname jobname

enter image description here

if I restart the POD, memory usage is about 100Mi

enter image description here

should use any jar switches to release the memory?

3 Answers

It seems to me your codes has memory leak which some objects are always being referenced such that GC cannot remove them.

The general idea to solve memory leak is to take the heap dump, analyse it and find out which objects occupy most of the memory in the heap such that you can review the related codes.

You can easily google about how to take the heap dump and what tools to use (e.g. Eclipse Memory Analyzer Tool) to analysis it such as this.

It may be a memory leak or it may be not. A lot of information is missing to be able to draw conclusion. Did you put a memory limit on your container? Container with a JVM tend to use a lot of memory even if nothing is running when the limit is high and if the JVM configuration is not tuned accordingly. With that said, it seems in your screenshot that your application is still running after the job was done, the Spring context and maybe the data used by the job still in memory if they were not cleaned properly.

Have you consider using a Job instead of a K8s Deployment for you Spring Batch Job? If that is a possibility, you should definitely do that instead, Spring Batch can easily be configured to be run inside a K8s Job, that would greatly simplify and optimize the memory management inside your cluster.

have you ever tried your batch job locally? using jstat -gc pid or using some wonderful tools such as JProfiler or Java VisualVM.

Related