Using OpenJ9 for running Microservices in Docker

Remember: New Open Source JVM optimized for Cloud and Microservices

Goal

Run a Java microservice application inside Docker with OpenJ9 JVM implementation.

Project Description

Sample SpringBoot 2 microservice with a simple REST resource implementation.

Docker image is using OpenJ9 JVM with optimized settings for Docker.

We are using a 128m max heap size here, you should tweak memory values in case of bigger applications.

BTW do you remember the last time you ran any Java application with 128m max heap size? :)

GitHub Repository

Dockerfile

docker-compose.yml

Instructions

Build Java Microservice

mvn -f microservice/pom.xml package

Build Docker Image

docker-compose build

Run Microservice in Docker

docker-compose up -d

Scale Microservice to N instances

docker-compose --scale app=N

Results with OpenJ9

First container startup:

Started DemoApplication in 4.143 seconds (JVM running for 4.949)

Second container startup:

Started DemoApplication in 1.116 seconds (JVM running for 1.382)

Container memory usage after startup: 56 MB

Container memory usage after 10min load: 66 MB

Results with OpenJDK 9 (for comparison)

First container startup:

Started DemoApplication in 1.941 seconds (JVM running for 2.423)

Second container startup:

Started DemoApplication in 1.606 seconds (JVM running for 1.932)

Container memory usage after startup: 193 MB

Container memory usage after 10min load: 241 MB

Conclusion

  • OpenJ9 has 3x smaller footprint compared to OpenJDK with HotSpot or Oracle JRE in the sample application.
  • OpenJ9 starts 30% faster than OpenJDK with HotSpot when Shared Classes are enabled.
  • The amount of memory and CPU used by OpenJ9 during and after load is less than OpenJDK with HotSpot.
  • OpenJ9 can compete with other VM based languages such as Node and Ruby. It can also run those languages in JVM using Eclipse OMR.
  • Once OpenJ9 is released it can become the smart choice for running cloud microservices applications.