I need to run a bunch of java processes, that I'm not sure, what their maximum heap usage can be. To make better use of server's heap memory I tried solution described in 1. I found in documentation, that basically GC needs to be called, that heap will be resized.
The G1 collector considers to resize the Java heap during a the Remark and the Full GC pauses only.
The problem I'm facing is that java is still using way more RES memory, that I'd expect. First example is Jenkins master. Here's Docker compose to start it:
version: '3.9'
services:
jenkins_master:
image: jenkins/jenkins:2.387.1-lts-jdk17
environment:
- JENKINS_OPTS=--prefix=/jenkins --sessionTimeout=60 --httpKeepAliveTimeout=3600000
- JAVA_OPTS=-DjenkinsMaster -Xms512M -Xmx4G -XX:MetaspaceSize=1G -XX:MaxMetaspaceSize=1G -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=1 -XX:+UseG1GC -XX:G1PeriodicGCInterval=1000
network_mode: host
volumes:
- /jenkins_artifacts/.jenkins_testing:/var/jenkins_home
logging:
driver: json-file
options:
max-size: 500m
restart: "unless-stopped"
ps aux
ps aux | grep jenkinsMas
user 73447 102 3.1 16632744 **4168532** ? Sl Sep25 10811:39 java -Duser.home=/var/jenkins_home -DjenkinsMaster -Xms512M -Xmx4G -XX:MetaspaceSize=1G -XX:MaxMetaspaceSize=1G -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=1 -XX:+UseG1GC -XX:G1PeriodicGCInterval=1000 -Djenkins.model.Jenkins.slaveAgentPort=50000 -Dhudson.lifecycle=hudson.lifecycle.ExitLifecycle -jar /usr/share/jenkins/jenkins.war --prefix=/jenkins --sessionTimeout=60 --httpKeepAliveTimeout=3600000
So, it's barely using 1GB of heap (and 128MB of metaspace), but 4GB of RES memory.
I also noticed, that if I leave VisualVM open, it will all of the sudden start using about 5GB of memory (but I wasn't using VisualVM in the example above).
Thank you very much.

