Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the peak memory usage in a maven build

Tags:

java

maven

I need to find out the peak memory usage of a maven build, can I rely on the final output given by successful maven build. Does 43M indicates the peak memory usage during the maven build. Thanks in advance.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.222 s
[INFO] Finished at: 2017-07-31T19:10:04+05:30
[INFO] Final Memory: 43M/636M
[INFO] ------------------------------------------------------------------------
like image 422
Kasun Siyambalapitiya Avatar asked Jul 31 '17 14:07

Kasun Siyambalapitiya


1 Answers

Here :

Final Memory: 43M/636M

43M is the used memory and 636M the current allocated memory (heap size) by the JVM at the end of the build.
But these information could not give you the peak value.

Why the used memory (43M) cannot be considered as the peak ?

  • Because the peak may have occurred before the end of the build.

Why the heap size (636M) cannot be considered as the peak ?

  • Because the peak may be superior to the heap size if the GC reduced the heap size between the peak and the end of the build .
    It may be the case for a very long build that performs intensive tasks at the beginning and lighter tasks then.

  • Because the peak may be inferior to the heap size if the GC has increased the heap size until this value but the application never needs to consume as much as memory.

To get the memory peak during the execution of the maven build, monitor the Java application (maven execution) with any JVM tool designed for : JVisualVM or JConsole for example.

Here's an screenshot of a maven build of a Spring Boot application monitored by JVisualVM that shows that neither the heap size or the used size at the end of build are the peak value :

enter image description here

like image 100
davidxxx Avatar answered Oct 06 '22 00:10

davidxxx