Reshaping the Java Language on the Cloud

ElasticHeap

Obviously, one of Java’s major weaknesses is its high resource consumption, particularly its memory usage by heaps. Even when no requests are processed and no objects are allocated, processes still reserve the full heap memory space to ensure the agile allocation and operation of memory resources during garbage collection.

ElasticHeap Practices in Alibaba

Scenario 1: Predictable Traffic Peaks

Scenario 2: Multiple Java Instances Running on a Single Server

Static Compilation

Many new applications on the cloud are developed by using the Go language to remove runtime dependencies. Statically compiled applications start up quickly, without the just-in-time compilation (JIT) ramp-up period. Then, how do we incorporate these advantages of the Go language into the Java code used by Alibaba?

Wisp2

Imagine that you develop a simple web service by using Vert.X and a quality assurance engineer asks you to perform stress testing on your web service in a 1C container with 2 GB memory capacity. You may find that your web service cannot match Go-compiled applications. This is because the coroutine model performs much better when the number of cores is small. But, is this problem caused by Java?

FDO

During Double 11, CPU usage peaked in the several minutes after midnight, when the big promotion began. Data analysis indicates that the main reason was that JIT compilation was triggered at midnight. The following is an example of the program logic: If (is1111(LocalDate.now())) {branch1} else {branch2 }. What this formula means is that, if branch2 is executed during the ramp-up period, JIT compilation is not performed on branch1. When branch1 is entered at midnight, deoptimization must be triggered to recompile the method. Now, let’s look at how AJDK solves the problem of deoptimization through profiling.

Principles and Adverse Impact of Deoptimization

When the JDK runs the code, it dynamically compiles the Java method through tiered compilation. For performance reasons, some optimistic assumptions are made based on data collected during high-level compilation, with optimal peak performance. Deoptimization occurs when these assumptions are not met. For example, if a code snippet in a hotspot method is only executed during the Double 11 Shopping Festival, this code snippet is not compiled during the ramp-up period. Deoptimization is triggered for the method when the code snippet is executed during Double 11.

Mitigation of Deoptimization Through Feedback Directed Optimization

Feedback directed optimization is used to improve compilation during the current runtime based on the compilation information from past JVM runtimes. For this, information about deoptimization during runtime is recorded in a file, which is read during the next runtime. Then, the recorded information is used to determine whether to make optimistic assumptions. This reduces the probability of de-optimization. The recorded information shows that deoptimization occurs in more than half of if-else statements. Therefore, our team provided a method of disabling all related optimistic assumptions on a path based on information about past occurrences of deoptimization in if-else statements.

Effect of Feedback Directed Optimization During Double 11

Feedback directed optimization was applied during the 2019 Double 11 Shopping Festival to solve the following two problems:

  1. Ramp-up was insufficient. In a stress test with a long ramp-up period, compilation and deoptimization occurred frequently as traffic increased.

Grace

ZProfiler is used to troubleshoot problems with Java applications in Alibaba. As the optimized and platform-based version of ZProfiler, Grace transforms the standalone architecture into a master/worker architecture and introduces a task queuing mechanism to reduce the workloads of worker threads with heavy loads. Grace is more maintainable and scalable and delivers a better user experience than ZProfiler. This lays a solid foundation for migrating tools and platforms to the cloud and developing open-source projects.

JDK 11

JDK 8 is a widely used classic version. Migration from JDK 6 and JDK 7 is complex but provides many benefits.

ZGC

ZGC is an important feature of JDK 11. Z Garbage Collector can keep the pause time within 10 ms in a heap ranging from dozens of gigabytes to several terabytes in size. With a short pause time, Z Garbage Collector is favored by Java developers because it removes the latency caused by long pause times typical in other garbage collectors.

  1. Z Garbage Collector improved the average response times and glitch metrics of clusters running online.

Summary

Alibaba’s custom JDK, AJDK has evolved from a traditional managed runtime. AJDK will continue to improve the development experience for cloud applications and provide more possibilities for upper-layer applications through underlying innovation.

Using AJDK on Dragonwell

Alibaba Dragonwell 8 is a free release version of OpenJDK. It features long-term support, including performance enhancements and security fixes. Alibaba Dragonwell 8 currently supports the x86–64/Linux platform. It can significantly improve stability, efficiency, and performance for large-scale Java applications deployed in data centers. Alibaba Dragonwell 8 is a “friendly fork” under the same licensing terms as the OpenJDK project. Alibaba Dragonwell 8 is compatible with the Java SE standard. You can use Alibaba Dragonwell 8 to develop and run Java applications. Alibaba Dragonwell 8 is the open-source version of AJDK, which is a custom version of OpenJDK used within Alibaba. AJDK is optimized for e-commerce, finance, and logistics and runs in the ultra-large Alibaba data center with more than 1,000,000 servers.

Original Source:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store