Spring Cloud Microservice Memory Usage

I run several microservices (Spring Cloud + Docker) on small / medium machines on AWS, and recently I found that these machines are often exhausted and require a reboot. I am studying the causes of this power loss, thinking about possible memory leaks or incorrect configurations on the instance / container.

I tried to limit the amount of memory that these containers can use:

docker run -m 500M --memory-swap 500M -d my-service:latest 

At the moment, my service (a standard spring cloud service with one single endpoint that writes material to Redis DB using spring-data-redis) has not even started.

The memory was increased to 760M , and it worked, but, controlling it with the help of the docker, I see that the minimum:

 CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS cd5f64aa371e 0.18% 606.9 MiB / 762.9 MiB 79.55% 102.4 MB / 99 MB 1.012 MB / 4.153 MB 60 

I added some parameters to limit the heap of JVM memory, but it doesn’t seem to reduce it very much:

 _JAVA_OPTIONS: "-Xms8m -Xss256k -Xmx512m" 

I run

  • Spring Cloud Brixton.M5
  • Spring Download 1.3.2
  • Java 8 (Oracle JVM)
  • Docker
  • Spring Redis 1.7.1 data

Is there a reason why such a simple service uses so much memory to run? Are there any features that I should disable to improve this?

+6
source share
2 answers

We explored a number of things in a similar setup from the perspective of the JVM itself. A quick way to save some memory when using Java 8 is to use the following options:

 -Xms256m -Xmx512m -XX:-TieredCompilation -Xss256k -XX:+UseG1GC -XX:+UseStringDeduplication 

G1GC is well documented, UseStringDeduplication reduces heap usage by deduplicating storing strings on the heap (we found about 20% in a JSON / XML web service type environment), and TieredCompilation is of great importance in using CodeCache (from 70 MB to 10 MB), as well about 10% less metaspace due to a startup time of about 10%.

+1
source

According to the Spring Installation Spring application page for download, you can configure the script to start the application using an environment variable or a configuration file with the JAVA_OPTS variable.

For example: JAVA_OPTS = -Xmx64m

-one
source

All Articles