spring boot microservice consumes a lot of memory in container deployed in ecs aws

Viewed 810

I have a microservice in spring boot which is deployed in a container with corretto 11 in ECS.

The component is deployed with 512MB and its initial consumption is close to 50%, as traffic increases, memory increases and is never freed, to the point where the task in ECS crashes and a new one must be started.

The following image shows the behavior of memory over time, as the traffic increases the times in which the tasks in ECS are up are less.

Memory Consumption in a Container on AWS ECS

Spring Boot Version: 2.4.3 JDK Image: Corretto 11

UPDATE:

I did a profiler and analysis of the heapdump and I see a high consumption in spring libraries.

Heapdump analysis with VisualVM

1 Answers

According to the screenshot, the problem seems to be in DefaultListableBeanFactory objects.

Please, check your code and make sure that you don't instantiate spring beans for every request. If so, you need to autowire them only once, statically.

For example, check the following solution: Memory leak in jboss service due to DefaultListableBeanFactory objects

Here is the explanation, on why there can be Memory leak in serializable bean factory management:

https://github.com/spring-projects/spring-framework/issues/12159?focusedCommentId=57240&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-57240

P.S. I don't think that there is a bug in Spring framework itself, but if so, then please, upgrade Spring Boot to the latest version. Maybe your version contains some bug, which causes memory leak.

See details in this reported issue: https://github.com/spring-projects/spring-framework/issues/25619

Related