×
Community Blog What There Is to Know About Alibaba Dragonwell 8

What There Is to Know About Alibaba Dragonwell 8

This blog explores newly announced Dragonwell 8, how you can install and use it and ways that you can participate in the development community.

By Lu Chuansheng, Senior Technical Expert at Alibaba Cloud Intelligence Department

Over the years, Alibaba Group has been involved in several, major, and large-scale Java application scenarios in the fields of e-commerce, finance, and logistics. Alibaba Cloud now wants to share the expertise learned through these large-scale applications of Java with the greater cloud community, and contribute to the greater community.

On March 21, 2019, Alibaba Cloud officially announced its new open-source project of the free distribution version of OpenJDK Alibaba Dragonwell 8. At the summit, Alibaba announced they want to establish the Dragonwell community to provide long-term JDK support for international Java users in addition to their user base in China. After being published as an open-source project, Alibaba Dragonwell 8 has now drawn attention from several Java developers both in China and abroad.

This blog, besides exploring what Dragonwell 8 is, will also look at how you can install and use Alibaba Dragonwell 8 and consider some way in which you can participate in the Alibaba Dragonwell 8 community.

What Is Alibaba Dragonwell 8

Alibaba Dragonwell 8 is a free distribution version of OpenJDK, which will offer long-term support, including performance enhancements and security fixes, from Alibaba Cloud. Alibaba Dragonwell 8 currently supports the X86-64/Linux platform. The addition of Dragonwell 8 can greatly improve the stability, efficiency, and performance of your large-scale Java application deployments in the data centers. Alibaba Dragonwell 8 is a "friendly fork" under the same licensing terms as the OpenJDK project and is compatible with the Java SE Standard. Users can use Alibaba Dragonwell 8 to develop and run Java applications. The open-source Alibaba Dragonwell 8 is the open-source version of the AJDK, a customized version OpenJDK used internally at Alibaba Group. AJDK is specifically optimized for e-commerce, finance, and logistics based on business scenarios and runs on the ultra large-scale Alibaba data center, housing well over 100,000 servers.

How to Install Alibaba Dragonwell 8

Currently, Alibaba Dragonwell 8 supports Linux x86-64 platform only and provides pre-compiled binary JDK packages. You can follow the two steps to install Alibaba Dragonwell 8.

  1. Download the pre-compiled binary JDK packages from the download page under the Alibaba Dragonwell 8 on GitHub.
  2. Unzip the downloaded tar packages to the installation directory.

After the installation is completed, simply point JAVA_HOME referenced by the application to the installation directory of Alibaba Dragonwell 8. Consider Tomcat 8.5.39 for example, to run Tomcat on Alibaba Dragonwell 8, simply use the following command when starting Tomcat:

JAVA_HOME=/path/to/dragonwell8/installation  sh tomcat/bin/catalina.sh start

To confirm that Tomcat is actually running on Alibaba Dragonwell 8, you can add the -showversion parameter to that Java command to print the JDK version information.

JAVA_HOME=/path/to/dragonwell8/installation JAVA_OPTS="-showversion" sh tomcat/bin/catalina.sh start

After Tomcat is started, you can see the version information about Alibaba Dragonwell 8 at the beginning of the tomcat/logs/catalina.out file.

1

How to use Alibaba Dragonwell 8

This sections discusses how you can use the various features of Alibaba Cloud Dragonwell 8. Currently, the preview view of Dragonwell 8 provides two features that have been in full production mode at Alibaba Group internally: JWarmUp and Java Flight Recorder. For both the features, JEP or patches have been submitted to the upstream OpenJDK community. Before the upstream merge is completed, we hope that Alibaba Dragonwell 8 users can use the two features in advance.

Use JWarmUp to Quickly Warm up Java Applications

To improve the execution efficiency, OpenJDK uses the JIT (just-in-time) compilation technology to dynamically compile Java byte code into highly optimized machine code. However, before this compilation is completed, Java code is run in interpreter mode, which is relatively inefficient.

When the application is started and business traffic just comes in, it is very likely that many Java methods begin to be compiled by using JIT and business requests are being executed by slow interpreters. The final result of this phenomenon is the extremely high system load and many user request timeouts. Many previous solutions to this problem is to use simulated traffic to warm up applications. The JWarmUp feature provides a new option for solving this problem, that is, to use the record of the previous execution and compilation of a Java virtual machine to warm up the current application to be run.

The following figure shows how JWarmUp functions.

2

A typical application scenario of JWarmUp is to release a new application version:

  1. JWarmUp first runs the Java application on a single machine in the beta environment for a short time and records and collects the metadata of actions made by the JIT compiler during this period of time.
  2. JWarmUp then copies the obtained metadata into each machine/container in production that contains the code of the new version.
  3. Finally, the metadata generated in the beta environment is loaded to machines in production by using the JWarmUp parameter to guide the machines in production to complete the JIT warmup in the process of starting the application.

By doing this, the application will show the best performance once a user request is made.

Collect warmup data

Again, consider Tomcat as an example, the following command line parameter can be added to collect the metadata generated in the beta environment during the JIT compilation, where the -XX:CompilationWarmUpLogfile= parameter specifies the path of the JWarmUp file generated.

JAVA_HOME=/path/to/dragonwell8/installation JAVA_OPTS="-XX:ReservedCodeCacheSize=512m -XX:CompilationWarmUpLogfile=$PWD/jwarmup.log -XX:+CompilationWarmUpRecording -XX:+CompilationWarmUp -XX:-TieredCompilation -XX:+DeoptimizeBeforeWarmUp -XX:CompilationWarmUpDeoptTime=30 -XX:+PrintCompilationWarmUpDetail" sh bin/catalina.sh start

Following this, this generated file can be transmitted onto machines in production by using OSS, SFTP or other methods.

Use recorded data to warm up Java applications

On machines in production, you can simply use the following parameters to start a new instance of Tomcat by using the previous warmup data. The -XX:CompilationWarmUpLogfile= parameter specifies the path of the JWarmUp file to be loaded. This file should be copied from the beta environment in the previous step to collect warmup data.

JAVA_HOME=/path/to/dragonwell8/installation JAVA_OPTS="-XX:ReservedCodeCacheSize=512m -XX:CompilationWarmUpLogfile=$PWD/jwarmup.log -XX:+CompilationWarmUp -XX:-TieredCompilation -XX:+DeoptimizeBeforeWarmUp   -XX:CompilationWarmUpDeoptTime=30 -XX:+PrintCompilationWarmUpDetail" sh bin/catalina.sh start

Use Java Flight Recorder to Analyze Java Application Performance

JFR (Java Flight Recorder) is an event-based performance analysis feature built in JVMs. This commercial feature began to be available starting in Oracle JDK7u4. The feature was made open source for JDK11 in 2018. However, support for JDK8 is not available.

Alibaba works together with companies like Red Hat, Azul, and Amazon to add support for this feature to JDK8. However, currently this patch has not been merged to OpenJDK8u. To allow you to obtain the support for this feature in advance, we have provided the JFR version ported by Alibaba in Alibaba Dragonwell 8.

It is extremely easy to use JFR. You only use command-line parameters or jcmd commands to control HotSpot and generate performance data into files. Then you can use the open-source JMC tool to open and analyze the generated files in the graphic interface.

Use JFR to Collect Performance Data

By default, the JFR feature is disabled in Alibaba Dragonwell 8. To enable the JFR feature, the command-line parameter -XX:+EnableJFR must be added. Alibaba Dragonwell 8 provides several options to collect performance data by using JFR.

A command-line parameter can be used in an application to specify that JFR begins to collect performance data immediately after the application is started. This is helpful for diagnosing startup problems. The following example code will collect JFR data for one minute once the JFR module in the Java process is initialized and return the data into a file named rec.jfr.

JAVA_HOME=/path/to/dragonwell8/installation JAVA_OPTS="-XX:+EnableJFR -XX:StartFlightRecording=duration=1m,filename=rec.jfr" sh bin/catalina.sh start

In addition, -XX:+EnableJFR alone can be added to an application and then jcmd commands can be used to collect data at any point in time after the application is started.

For example, you can use the following command to start Tomcat:

JAVA_HOME=/path/to/dragonwell8/installation JAVA_OPTS="-XX:+EnableJFR" sh bin/catalina.sh start

To collect data for analysis, simply use the PID of the destination Tomcat process to run the corresponding jcmd command of JFR. For example, in Tomcat, use the following command to collect data for 10 seconds starting at a specific point in time:

$ ps ax | grep tomcat
 77522 pts/18   Sl+    0:08 /home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39/../j2sdk-image/bin/java -Djava.util.logging.config.file=/home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -XX:+EnableJFR -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39/bin/bootstrap.jar:/home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39/bin/tomcat-juli.jar -Dcatalina.base=/home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39 -Dcatalina.home=/home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39 -Djava.io.tmpdir=/home/chuansheng.lcs/dw_test/apache-tomcat-8.5.39/temp org.apache.catalina.startup.Bootstrap start
 98451 pts/22   S+     0:00 grep --color=auto tomcat

$ dragonwell8_home/bin/jcmd 77522 JFR.start duration=10s filename=$PWD/rec3.jfr
77522:
Started recording 3. The result will be written to:

/home/my/workdir/rec3.jfr

After 10 seconds, the /home/my/workdir/rec3.jfr JFR file is generated. You can use JMC to analyze that file.

You can also directly start JFR to collect data without specifying the duration of the data collection and manually dump all the data generated into a file at a time when necessary.

$ dragonwell8_home/bin/jcmd 2823 JFR.start filename=$PWD/rec4.jfr
2823:
Started recording 4. No limit specified, using maxsize=250MB as default.

Use JFR.dump name=4 to copy recording data to file.

$ dragonwell8_home/bin/jcmd 2823 JFR.dump name=4 filename=rec4.jfr
2823:
Dumped recording "Recording-4", 332.7 kB written to:

/path/to/my/workdir/rec4.jfr

Use JMC for Performance Analysis

JFR records Java application performance data in a binary file. With JMC (Java Mission Control), we can analyze a specific set of performance data in a graphic interface. JMC is an open-source tool. It is not included in Alibaba Dragonwell 8. To use this tool, you can download it at the OpenJDK official website https://jdk.java.net/jmc/

Note that JMC 7.0 or later is required to analyze JFR data files generated by using Alibaba Dragonwell 8.

After opening JMC, you can click specific items on the left side to analyze events that occurred during the sampling in detail.

3

Support for Diagnosis and Debugging

Alibaba Dragonwell 8 also has some convenient and built-in diagnosis features discussed below.

Alerting on the Assignment of Large Objects

The new JVM parameter -XX:ArrayAllocationWarningSize= can be used for this purpose. For example, the following code assigns a relatively large array.

public static void main(String[] args) {
    doAlloc(32 * 1024 * 1024 + 1);
}
private static Object doAlloc(int size) {
    return new byte[size];
}

If the ArrayAllocationWarningSize option is added when the code is run, it will print the Java stack running while this array is assigned.

4

Detailed Support for ParNew GC Logs

By default, the CMS (Concurrent Mark Sweep) algorithm is used in Alibaba Dragonwell 8 and the ParNew algorithm is used for the young generation. Therefore, the two built-in enhancements are provided for ParNew GC logs.

  • You can set the PrintYoungGenHistoAfterParNewGC option by using the jinfo tool so that a object type histogram for the young generation can be printed at the end of the next Young GC. To do this, you can use the following command:
jinfo -flag +PrintYoungGenHistoAfterParNewGC <pid>

After this printing operation is completed, the option will be reset back to false to prevent too much output. The following content is a typical output example:

5

  • -XX:+PrintGCRootsTraceTime can be used to print details about CPU time for processing each type of GC root sets. The following content is an output example:

6

Support for streamlined HeapDumps

The jmap tool in Alibaba Dragonwell 8 supports a new dump option - mini, which allows skipping the content of all arrays of original type when generating HeapDumps. This option significantly reduces the size of generated HeapDump files and is especially helpful in scenarios where it is only required to check types and object relationships.

The following figure shows a code sample.

7

Participate in construction of the Alibaba Dragonwell community

The Alibaba Dragonwell community provides long-term support for JDK versions. You can obtain support, participate in discussions, and raise your opinions through the following channels:

The Issues page of the Alibaba Dragonwell project on GitHub

References

[1] Oracle Java 8 official document: https://docs.oracle.com/javase/8/
[2] OpenJDK 8 project homepage: https://openjdk.java.net/projects/jdk8u/
[3] Alibaba Dragonwell 8 project: https://github.com/alibaba/dragonwell8
[4] Alibaba Dragonwell 8 Developer Guide: https://github.com/alibaba/dragonwell8/wiki/Developer-Guide

0 0 0
Share on

Alibaba Developer

35 posts | 10 followers

You may also like

Comments