Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the memory footprint of the JVM and how can I minimize it?

I just wanted to know what the actual footprint of the JavaVM (Sun, Linux) is when one starts to start to spawn multiple processes of JVMs. When I remember well those should share the rt.jar (and maybe beyond?). Does those JVM share the JIT cache (all JVM feature the same Classpath)?

Is there anything I can do to reduce the overhead of multi-instance JVM? (beside of setting smaller limits for the heap)?

Anything I can do while programming the application?

Can I share memory areas? Maybe share mapped memory blocks?

like image 969
Martin Kersten Avatar asked Jul 24 '16 12:07

Martin Kersten


People also ask

What is JVM memory footprint?

In a Java program, the memory footprint is predominantly made up of the runtime environment in the form of Java virtual machine (JVM) itself that is loaded indirectly when a Java application launches.

How do I reduce Java memory footprint?

Set the Heap Size The most obvious place to start tuning the memory footprint is the Java heap size. If you reduce the Java heap size by a certain amount you will reduce the memory footprint of the Java process by the same amount. You can however not reduce the Java heap size infinitely.

What is JVM memory usage?

An interesting area when sizing the JVM is the JIT's code cache. By default, the HotSpot JVM will use up to 240MB. If the code cache is too small the JIT will run out of space to store its output and performance will suffer as a result. If the cache is too large, memory may be wasted.


2 Answers

To complement other answers, here is a couple of insightful articles listing typical JVM memory footprint values and ways to measure them:

https://spring.io/blog/2015/12/10/spring-boot-memory-performance

http://trustmeiamadeveloper.com/2016/03/18/where-is-my-memory-java/

like image 99
Vadzim Avatar answered Sep 19 '22 12:09

Vadzim


Probably it will be only a partial answer.

What is the memory footprint of the JVM

The full footprint of a Java app consists of Heap space and non-heap space (let me call it this way). Just a couple of examples of what resides in non-heap space: PermGen or Metaspace, derect allocation from code (malloc), NIO also uses native memeory.

how can I minimize it?

The heap usually occupies the biggest part of you footprint. So, I would start with it.

As for the non-heap space, you can minimize: PermGen (If you max size is redundant), Thread stacks (They are quite large, especially in 64-bit JMMs) and Code cache (insted of performance, of course).

Does those JVM share the JIT cache

In normal conditions (and I'm not aware of others) every process has its own footprint. That's actually what differs a process from a thread. And back to multiple JVMs, each JVM is a separate process.

should share the rt.jar

If you start Java from the same directory (the same installation), of course, they share the same rt.jar, but only as a source of classes. For example, the String class will be loaded as many times as a number of running JVMs.

like image 43
Average Joe Avatar answered Sep 19 '22 12:09

Average Joe