Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot memory consumption increases beyond -Xmx option

I noticed Spring Boot application does not obey the amount of memory set via Xmx option. For example: java -Xss64m -Xmx64m -jar test.jar

I also printed on console the amount of memory really used by application at startup, and shows: Max memory: 61M

long maxBytes = Runtime.getRuntime().maxMemory();
System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

When I open Windows processes before accessing any web page, it shows +-105M, so how can Java say 61M?

After accessing any web page it goes from +-125M to +-135M. Why is there such increase? It should give "java.lang.OutOfMemoryError: PermGen space" but do not increase this way.

It makes me get worried, if many applications could run out of memory at the server. By the way, I am using Java 1.8_45

like image 863
Carlos Alberto Avatar asked Jun 29 '15 21:06

Carlos Alberto


People also ask

What are the disadvantages of spring boot?

Disadvantages of Spring BootSpring Boot creates a lot of unused dependencies, resulting in a large deployment file; The complex and time-consuming process of converting a legacy or an existing Spring project to a Spring Boot application; Not suitable for large-scale projects.

How much RAM does spring boot use?

The default value for the minimum heap is 8 Mb or 1/64th of the physical memory within the 8 Mb to 1 Gb range. The default value for the maximum heap is 1/4th of the physical memory for physical memory greater than 192 MB, otherwise, it's 1/2th of the physical memory.

How does spring boot application reduce memory usage?

You can get a simple Spring Boot app down to around 72M total by using the following JVM options. With -XX:MaxRAM=72m This will restrict the JVM's calculations for the heap and non heap managed memory to be within the limits of this value.

What is @document annotation in spring boot?

@Document is an annotation provided by Spring data project. It is used to identify a domain object, which is persisted to MongoDB. So you can use it to map a Java class into a collection inside MongoDB. If you don't use Spring Data, you don't need this annotation.


1 Answers

After monitoring the Spring Boot application, I found out some possible reasons such as:

  1. Number of http threads (Undertow starts around 50 threads per default, but you can increase / decrease via property the amount of threads needed)
  2. Access to native routines (.dll, .so) via JNI
  3. Static variables
  4. Use of cache (memcache, ehcache, etc)
  5. If a VM is 32 bit or 64 bit, 64 bit uses more memory to run the same application, so if you don't need a heap bigger than 1.5GB, so keep your application runnnig over 32 bit to save memory.
like image 63
Carlos Alberto Avatar answered Oct 25 '22 20:10

Carlos Alberto