Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Spring Boot default memory settings?

For example if I run/debug simple spring boot app from IDE without definitions, what size of initial heap size, max heap size and stack size (-Xms, -Xmx, -Xss) will be set?

like image 480
Nikolay Shabak Avatar asked Jul 25 '16 09:07

Nikolay Shabak


People also ask

What is the default XMS and XMX?

The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. The Xms flag has no default value, and Xmx typically has a default value of 256 MB.

What is the default Java memory allocation?

The Java™ virtual machine (JVM) heap size setting directly relates to how many server instances can be started within a dynamic cluster on a specific node. You might need to modify the JVM heap size setting based on your environment configuration. The default value is 256 MB.

How much memory does spring boot use?

The Spring Boot autoconfiguration premium, measured this way, is about 1MB heap and 4MB non-heap.

How do I monitor memory usage of spring boot?

We can view how much of memory consumption in spring boot app, in this way. Now open the CMD and type jconsole and hit enter. Now you can see a window like below and it will appear application that previously ran in Local Process section. Select springboot-example.


1 Answers

By default Spring Boot app will use JVM default memory settings.

Default heap size

In case your physical memory size is up to 192 megabytes (MB) then default maximum heap size is half of the physical memory.

In case your physical memory size is more than 192 megabytes then default maximum heap size is one fourth of the physical memory.

For example, if your computer has 128 MB of physical memory, then the maximum heap size is 64 MB, and greater than or equal to 1 GB of physical memory results in a maximum heap size of 256 MB.

The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, called the initial heap size, is allocated during JVM initialization. This amount is at least 8 MB and otherwise 1/64th of physical memory up to a physical memory size of 1 GB.

The maximum amount of space allocated to the young generation is one third of the total heap size.

You can check default values specific to you machine with the following command

Linux:

java -XX:+PrintFlagsFinal -version | grep HeapSize

Windows:

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Reference:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size

Default thread stack size

The default thread stack size varies with JVM, OS and environment variables.

To find out what your default thread stack size is on your platform, use

In Linux:

java -XX:+PrintFlagsFinal -version | grep ThreadStackSize

In Windows:

java -XX:+PrintFlagsFinal -version | findstr ThreadStackSize

like image 88
Eugene Maysyuk Avatar answered Sep 19 '22 14:09

Eugene Maysyuk