In this article, see how to use the OpenJ9 JVM with Quarkus applications and see the memory usage results. Talk about those things in detail
According to the definition on the home page, Quarkus is "Kubernetes native Java stack customized for OpenJDK HotSpot and grailvm". Since I'm a big fan of OpenJ9, I quickly measured the memory usage of my reactive sample application, where I ran microservices once using OpenJ9 and HotSpot.
OpenJ9 is a Java JVM, which was opened from IBM 2-3 years ago. It is basically the same JVM that IBM uses in hundreds of products and products. Happily, compared with Hotspot, it not only has a 42% reduction in startup time, but also a 66% reduction in memory footprint. View the document.
I used OpenJ9 in the adopt openjdk, and you can choose between HotSpot and OpenJ9. Read my previous blog to learn more about the other benefits offered by adopt openjdk.
Memory usage results
This is my little test result. This image is from the Quarkus website. All of the orange content is what I added for OpenJ9.
I ran the same service, which uses OpenJ9 and HotSpot to access the database. I deployed two versions of the service from scratch and warmed it up by calling their rest APIs. Later, I called "docker stats | grep article is valid". The HotSpot is displayed as 149.8MiB and OpenJ9 as 59.77MiB.
How to test
I used the sample application, which is part of the cloud native starter project. Microservices provide REST API s that perform CRUD operations on PostgreSQL databases.
To run microservices using OpenJ9 in Minikube, call the following command.
1
$ git clone https://github.com/IBM/cloud-native-starter.git $ cd cloud-native-starter/reactive $ sh scripts/start-minikube.sh $ sh scripts/deploy-kafka.sh $ sh scripts/deploy-postgres.sh $ sh scripts/deploy-articles-reactive-postgres.sh $ curl ... [invoke command to trigger APIs returned by previous command] $ docker stats | grep articles-reactive
I used the following Dockerfile:
FROM adoptopenjdk/maven-openjdk11 as BUILD COPY src /usr/src/app/src COPY pom.xml /usr/src/app WORKDIR /usr/src/app RUN mvn package FROM adoptopenjdk/openjdk11-openj9:ubi-minimal ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" ENV AB_ENABLED=jmx_exporter RUN mkdir /opt/shareclasses RUN chmod a+rwx -R /opt/shareclasses RUN mkdir /opt/app COPY --from=BUILD /usr/src/app/target/lib/* /opt/app/lib/ COPY --from=BUILD /usr/src/app/target/*-runner.jar /opt/app/app.jar CMD ["java", "-Xmx128m", "-XX:+IdleTuningGcOnIdle", "-Xtune:virtualized", "-Xscmx128m", "-Xscmaxaot100m", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/app/app.jar"]
To use Hotspot, replace the Dockerfile with the contents of Dockerfile.Hotspot and run the same command.
FROM adoptopenjdk/maven-openjdk11 as BUILD COPY src /usr/src/app/src COPY pom.xml /usr/src/app WORKDIR /usr/src/app RUN mvn package FROM fabric8/java-alpine-openjdk11-jre ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" ENV AB_ENABLED=jmx_exporter COPY --from=BUILD /usr/src/app/target/lib/* /deployments/lib/ COPY --from=BUILD /usr/src/app/target/*-runner.jar /deployments/app.jar ENTRYPOINT [ "/deployments/run-java.sh" ]
Thank you for reading!