Search code examples
garbage-collectionquarkusjib

change GC in quarkus jib build docker container


How can the default GC be changed in quarkus docker image using jib as building engine?

I have tried with settings in application.yaml but got duplicate gc defined error as using the following parameter it writes the parameters to JAVA_OPTS env variable

quarkus.jib.jvm-additional-arguments: -XX:+UseZGC,-XX:+ZGenerational

and the jvm command in docker already has this which is there by default using JIB

java -XX:MaxRAMPercentage=80.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -Djava.util.logging.manager=org.jboss.logmanager.LogManager -cp . -jar /home/jboss/quarkus-run.jar
    

Solution

  • The reason you are seeing such behavior is because the default base image used by quarkus-container-image-jib is registry.access.redhat.com/ubi8/openjdk... which uses this script to determine the JVM launch params.

    You can take a look here to see all the options you can set that influence the script. The environment variable that influnces the GC used is GC_CONTAINER_OPTIONS, so the first thing you need to do is:

    quarkus.jib.environment-variables.GC_CONTAINER_OPTIONS=-XX:+UseZGC
    

    If you additionally want to use Generational ZGC, you need to also configure

    quarkus.jib.jvm-additional-arguments=-XX:+ZGenerational
    

    Using two different syntaxes is definitely clunky, so I have opened this issue to improve the situation.