Turbocharge Cloud-Native Apps
Several things are essential for cloud-native apps, including fast startup and low memory consumption. These can be achieved for Java by using GraalVM Native Image. This is where PGO (Profile Guided Optimization) helps to maximize performance across the several dimensions of optimization.
Increasingly, the key differentiator between these super apps (social platforms, live streaming, and fintech) is the speed at which they can startup and synthesize market data into opportunities and orders.
This means that the performance and responsiveness of their cloud platform is key to success. Fundamental to such super apps is minimizing latency while improving the throughput across the entire duration of the payment transaction, trade execution process, or live media stream. It's a sprint from the start to finish.
What is Profile Guided Optimization
Profile Guided Optimization (PGO) collects data about the typical execution of a program and then uses this to create turbocharged cloud-native apps. PGO requires running relevant workloads before building a cloud-native application. The optimized code runs immediately at startup, without a “warmup” curve. See the attached diagram showing the famous Petclinic application.
Outcome
The significant performance improvement can be seen across several areas including reduced build memory, lower memory footprint, smaller app size, faster startup, and higher throughput, see table below for metrics.
Technique
This is a test to see PGO improvement over the standard native image using Petclinic (a sample Spring-based application, specifically for this test we are using the Spring Boot famous Petclinic sample with JDBC persistence). The throughput comparison before vs after PGO is measured using Jmeter JMX for Petclinic.
Before: Native Image without PGO for Petclinic
Amitpals-MacBook-Pro-2:petclinic-jdbc adhillon$ ./build.sh
=== Building petclinic-jdbc sample ===
Packaging petclinic-jdbc with Maven
Unpacking petclinic-jdbc-0.0.1-SNAPSHOT.jar
Compiling petclinic-jdbc with GraalVM Version 20.2.0 (Java Version 1.8.0_261)
SUCCESS
Testing executable 'petclinic-jdbc'
SUCCESS
Build memory: 7.64GB
Image build time: 492.6s
RSS memory: 64.0M
Image size: 106.2M
After: Native Image with PGO for Petclinic
Amitpals-MacBook-Pro-2:petclinic-jdbc adhillon$ ./build.sh
=== Building petclinic-jdbc sample ===
Packaging petclinic-jdbc with Maven
Unpacking petclinic-jdbc-0.0.1-SNAPSHOT.jar
Compiling petclinic-jdbc with GraalVM Version 20.2.0 (Java Version 1.8.0_261)
SUCCESS
Testing executable 'petclinic-jdbc'
SUCCESS
Build memory: 6.77GB
Image build time: 523.4s
RSS memory: 62.8M
Image size: 95.1M
Technology
- GitHub: https://github.com/amitpal-source/spring-native/tree/master/spring-native-samples/petclinic-jdbc
- GraalVM: A High-Performance Virtual Machine that can produce Cloud-Native Applications. https://www.oracle.com/java/graalvm/
Conclusion
GraalVM native image allows applications to start instantly and reduce memory requirements, making them perfect for cloud deployments. With PGO, native executables achieve even greater strides within the dimensions of optimization, startup time improvements of up to 23%, reduced application size, and build memory by 10% and 11% respectively, versus the standard native image with over 100% faster startup times comparable to Java HotSpot.
Acknowledgments
https://springone.io/2020/sessions/the-path-towards-spring-boot-native-applications
Thanks to the collaborative support of Oracle Labs Engineering: Alina Yurenko, Munish Chouhan, Shaun Smith, and Vojin Jovanovich.