Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Add new blog post about default heap size on JVM
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
content/posts/til/default-heap-configuration-in-openjdk.fr.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: "TIL : Configuration de la mémoire par défaut dans OpenJDK" | ||
date: 2021-02-16T17:11:50+01:00 | ||
draft: false | ||
toc: false | ||
images: | ||
tags: | ||
- java | ||
- today I learnt | ||
--- | ||
Il s'agit du premier billet de la série "Today I learnt" (TIL, ou aujourd'hui j'ai appris en français). | ||
Dans cette série, comme son nom l'indique, je vais écrire sur tout un tas de choses que je découvre. | ||
Le but de tout cela est de me permettre de me souvenir plus facilement de certaines choses et, bien sûr, de les partager afin que d'autres n'aient pas de mal à les trouver. | ||
|
||
Donc, cet après-midi, quelqu'un m'a demandé quelle était la configuration mémoire d'un tomcat s'exécutant dans Docker. | ||
Nous n'avons pas défini de configuration particulière pour le tomcat, à l'exception du déploiement de notre application, donc la configuration par défaut est utilisée. | ||
|
||
Donc, la question est devenue : | ||
|
||
> Quelle est la configuration mémoire par défaut d'une JVM OpenJDK 8 ? | ||
D'après la [documentation Oracle](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html), _la valeur par défaut est choisie au runtime selon la configuration du système._ | ||
|
||
Il semble que cela dépende de l'architecture du serveur, de la mémoire système et du type de VM (serveur ou client). | ||
|
||
Pour les configurations client, comme décrit dans le [Guide de tuning du GC](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#sthref30), la taille maximale de la heap est la moitié de la mémoire physique si celle-ci est inférieure à 192 mégaoctets (Mo) et sinon à un quart de la mémoire physique si celle-ci est inférieure à 1 gigaoctet (Go). | ||
|
||
Pour les configurations serveur, comme décrit dans [le même guide](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#sthref31), la taille maximale de la heap est 1/4 de la mémoire physique, limité à 1 gigaoctet pour les JVM 32 bits et limité à 32 gigaoctets pour les JVM 64 bits. | ||
|
||
Un moyen simple de savoir quelle est la valeur par défaut de votre JVM sur votre environnement est d'exécuter la commande suivante : | ||
|
||
```bash | ||
java -XX:+PrintFlagsFinal -version | grep MaxHeapSize | ||
``` | ||
|
||
Le résultat pour notre JVM tournant dans un conteneur Docker est | ||
|
||
```text | ||
uintx MaxHeapSize := 16833839104 {product} | ||
openjdk version "1.8.0_242" | ||
OpenJDK Runtime Environment (build 1.8.0_242-b08) | ||
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode) | ||
``` | ||
|
||
La valeur est indiquée en octets. | ||
Donc, ici, la valeur par défaut est 16 Go, ce qui correspond à un quart de la mémoire physique de l'hôte (64 Go). | ||
|
||
La commande `java -XX:+PrintFlagsFinal -version` affiche de nombreuses informations (plusieurs centaines de paramètres), comme la configuration de la mémoire et du garbage collector. |
47 changes: 47 additions & 0 deletions
47
content/posts/til/default-heap-configuration-in-openjdk.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: "TIL: Default Heap Configuration in OpenJDK" | ||
date: 2021-02-16T17:11:50+01:00 | ||
draft: false | ||
toc: false | ||
images: | ||
tags: | ||
- java | ||
- today I learnt | ||
--- | ||
This is the first blog post in the "Today I learnt" (TIL) series. | ||
In this series, as its name suggests, I'll write about random things I learn. | ||
The purpose of all this is to make it easier for me to remember things and, of course, to share it so that others don't struggle to find it. | ||
|
||
So, this afternoon, someone asked me what are the heap configuration of a docker-based tomcat. | ||
We haven't set any particular tomcat configuration, except for our app deployment, so the default one is used. | ||
|
||
So, now, the question is: | ||
|
||
> What is the default heap configuration of an OpenJDK 8 JVM? | ||
According to [Oracle documentation](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html), _the default value is chosen at runtime based on system configuration._ | ||
It appears it depends on the server architecture, the system memory and the VM type (server or client). | ||
|
||
For client configurations, as described in [GC Tuning guide](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size), the default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes (MB) and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte (GB). | ||
|
||
For server configurations, as described in [the same guide](https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html#sthref5), the default maximum heap size is 1/4 of the physical memory up to 1 gigabyte for 32-bits JVMs and to 32 gigabytes for 64-bits JVMs. | ||
|
||
A simple way to know what is the default value for your JVM on your environment is to run the following command. | ||
|
||
```bash | ||
java -XX:+PrintFlagsFinal -version | grep MaxHeapSize | ||
``` | ||
|
||
The result for our JVM inside the docker container is: | ||
|
||
```text | ||
uintx MaxHeapSize := 16833839104 {product} | ||
openjdk version "1.8.0_242" | ||
OpenJDK Runtime Environment (build 1.8.0_242-b08) | ||
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode) | ||
``` | ||
|
||
The value is displayed in bytes. | ||
So, here, the default value is 16 GB which is one quarter of the host memory (64 GB). | ||
|
||
The `java -XX:+PrintFlagsFinal -version` command displays a lot of information (several hundreds of parameters), such as the heap space size and the selected garbage collector. |