Faster Payara Micro Startup Times with OpenJ9

Photo of Patrik Duditš by Patrik Duditš

One of the performance metrics that are frequently compared  by developers are startup times. Payara Server is designed to be manageable at runtime, with a central management server (DAS - domain administration server) and multiple instances, and as such is not optimized for extremely fast startup time. Payara Micro on the other hand, is optimized to run predefined workloads with a stable configuration at runtime, and is therefore a better fit for for comparing start up time metrics.

In this blog, let's take a look at how you can configure Payara Micro for fast startup time by utilizing the class data sharing feature of Eclipse OpenJ9.

What is Eclipse OpenJ9?

Eclipse OpenJ9 is an independent Java Virtual Machine implementation which is freely available from the Eclipse Foundation.

Compared to OpenJDK-based virtual machines, OpenJ9 has much better support for class data sharing. Class data sharing is an optimization technique, where metadata and pre-compiled versions of the class are stored in an auxiliary file, and therefore classes do not need to be parsed and partially compiled into bytecode at each startup of the JVM. This improves startup time of the server.

Such a feature is also present in the OpenJDK, but support for dynamic classloaders is only starting to take shape with Java 13, whereas OpenJ9 offers support for Java 8 already.

Installing OpenJ9

The best approach to obtaining OpenJ9 binaries is through AdoptOpenJDK. In our examples we will be running on an Ubuntu machine, and using their APT repository:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | \
sudo apt-key add -
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

We'll use JDK11 for the demonstration:

sudo apt install adoptopenjdk-11-openj9

Startup Time With and Without the Data Grid

Let's see how Payara Micro behaves without class data sharing active:

wget https://repo.maven.apache.org/maven2/fish/payara/extras/payara-micro/5.194/payara-micro-5.194.jar
JAVA=/usr/lib/jvm/adoptopenjdk-11-openj9-amd64/bin/java
$JAVA -jar payara-micro-5.194.jar

Out of the box, I got a startup time around 10 seconds on Azure Standard D4s v3 virtual machine (4 vCPUs, 16 GiB memory).

One of the largest parts of runtime initialization is the Hazelcast startup and discovery. Hazelcast is a high performance data grid bundled with Payara Micro. If your deployment does not need data sharing amongst instances, or web session replication, it is safe to turn it off. The most obvious way to do that is to pass the command line option --nocluster to java, but it is also possible to disable it via an environment variable. Environment variables are case sensitive on Linux, so use this exact casing:

export payaramicro_noCluster=true

With clustering disabled, the server's startup times drop to around 2.7 seconds. Now, let's see how class data sharing will help us further.

Configuring Class Data Sharing for Payara Micro

The default behavior of Payara Micro is to expand its runtime files into a temporary directory and delete them afterwards. Class data sharing likes to work on fixed paths, and is very eager to invalidate the caches on any change of the files.

We will therefore instruct Payara Micro to used a fixed directory by means of using a fixed root directory, and we'll also instruct the JVM to disregard timestamps of loaded jar files, as they are overwritten at every boot:

$JAVA -Xshareclasses:name=payara-micro,noTimestampChecks \
-jar payara-micro-5.194.jar --noCluster --rootDir micro-root

The first run will be a bit slow as the cache is being created, but subsequent runs will complete in just under 1.5 seconds!

With datagrid enabled, Payara Micro with class data sharing boots in about 6 seconds, so it improves startup time by almost 40%.

You can learn more about class data sharing and its diagnosis in OpenJ9 Class sharing tutorial.

Making Payara Micro Start Faster

Turning off clustering capabilities of Payara Micro when they are not needed and enabling class data sharing gives significant boost to startup time. When baking these optimizations into Docker image, DataGrid configuration can be performed via environment variables in addition to the command line.

We are planning to bring more features in upcoming releases of Payara Micro to optimizing startup sequence. For example, we plan to make steps to warm up class data caches simpler to perform during Docker image build and use these for our official image as well. Subscribe to our blog for updates and keep an eye on the release notes for new features and enhancements to the Payara Platform.

Try Payara Micro

Payara Micro Download

 

 

 

Comments