Spring Boot 3.0 本次带来最大的改动就是 GraalVM 原生镜像的支持,也是官方文档中强调的他们花费时间精力比较多的部分。 GraalVM 技术作为JRE的替代方案,其通过预先编译(Ahead Of Time,AOT)等技术对 Java 应用进行预先编译,让 Spring 在运行应用时掌握更多应用有关的信息,让整个应用启动速度更快。另外,通过编译工具在编译过程中通过消除一些不必要的内容可以让最终的应用更小,占用内存更低。对于一些对启动速度要求非常高的场景,比如 Serverless、FaaS 场景非常友好! 本次 Spring Boot 3.0 直接将其正式从 Spring Native 迁入到 Spring Boot 中来,也预示着该项技术开始逐渐走向成熟,Spring生态开始迈入 GraalVM 阶段!
Spring Boot 3.0 本次带来最大的改动就是 GraalVM 原生镜像的支持,也是官方文档中强调的他们花费时间精力比较多的部分。 GraalVM 技术作为JRE的替代方案,其通过预先编译(Ahead Of Time,AOT)等技术对 Java 应用进行预先编译,让 Spring 在运行应用时掌握更多应用有关的信息,让整个应用启动速度更快。另外,通过编译工具在编译过程中通过消除一些不必要的内容可以让最终的应用更小,占用内存更低。对于一些对启动速度要求非常高的场景,比如 Serverless、FaaS 场景非常友好! 本次 Spring Boot 3.0 直接将其正式从 Spring Native 迁入到 Spring Boot 中来,也预示着该项技术开始逐渐走向成熟,Spring生态开始迈入 GraalVM 阶段!
*跟 JVM 编译部署方式相比,GraalVM 具有以下特点:*
@ -13,17 +13,17 @@ Spring Boot 3.0 本次带来最大的改动就是 GraalVM 原生镜像的支持
注意事项:RocketMQ 应用通过上述命令进行 hint 文件生成过程中,可能会出现配置信息扫描不全问题,可参考 https://github.com/alibaba/spring-cloud-alibaba/issues/3101[相关issue],Sentinel应用通过上述命令进行 hint 文件生成过程中,可能会遇到如下问题,可参考 https://github.com/alibaba/Sentinel/issues/3012[相关issue]。
@ -13,9 +13,9 @@ One of the biggest changes of Spring Boot 3.0 is the support for GraalVM native
* Without lazy class loading, everything in the executable will be loaded into memory at startup.
* The supported Java applications have some limitations in some aspects. Therefore, it is not guaranteed that all the previous Java applications can directly use GraalVM technology for application construction, and there is a certain probability of incompatible exceptions.
Part of the middleware clients included in Spring Cloud Alibaba 2022.0.0.0 version of this release have completed the adaptation of constructing GraalVM native applications. The following is a sample application related to service registration, discovery module supported by the community. After upgrading to Spring Boot 3.0, GraalVM is used to build a native application image to test the startup speed and runtime usage. (Sentinel, Seata and RocketMQ are still being adapted. The following test process is simulated for 5 times respectively under the environment of MacOS 11.4, 2.6GHz 6-Core Intel Core i7 processor and 16G memory) :
Part of the middleware clients included in Spring Cloud Alibaba 2022.0.0.0 version of this release have completed the adaptation of constructing GraalVM native applications. The following is a sample application related to service registration, discovery module supported by the community. After upgrading to Spring Boot 3.0, GraalVM is used to build a native application image to test the startup speed and runtime usage. The following test process is simulated for 3 times respectively under the environment of MacOS 11.4, 2.6GHz 6-Core Intel Core i7 processor and 16G memory) :
From the above comparison, we can see that the latest Spring Cloud Alibaba application that supports Spring Boot 3.0 based on GraalVM will reduce application's startup time, runtime memory usage and application package size. For example, Among them, the startup speed of the service registration consumption application is increased by nearly 10 times, and the running memory usage is reduced by nearly 2/3 compared with the original, which has a very obvious effect. This gives the cloud native era, hosting in the cloud application has brought significant advantages, so that it can be faster elastic expansion and contraction capacity and reduce the overall cost of the enterprise cloud!
@ -23,29 +23,30 @@ From the above comparison, we can see that the latest Spring Cloud Alibaba appli
==== Build the project
Among all the components supported by Spring Cloud Alibaba for Spring Boot 3.0 this time, Nacos 2.1.1-RC already supports GraalVM technology to build applications. Next, we'll look at the components that use GraalVM to compile and run the application
Among all the components supported by Spring Cloud Alibaba for Spring Boot 3.0 this time, Nacos 2.1.1 already supports GraalVM technology to build applications. Next, we'll look at the components that use GraalVM to compile and run the application
The project construction can be carried out according to the general Spring Cloud Alibaba application construction method. The following are the relevant dependencies that must be added:
@ -105,6 +106,8 @@ After running all the test cases, we found the following hint files are generate
- proxy-config.json:Proxy hint file
- jni-config.json:JNI hint file
Note: During the generation of the hint file by the RocketMQ application through the above command, incomplete scanning of configuration information may occur, please refer to https://github.com/alibaba/spring-cloud-alibaba/issues/3101[related issues], During the generation of the hint file by the above command, the Sentinel application may encounter the following problems, please refer to https://github.com/alibaba/Sentinel/issues/3012[related issues].
==== Build native image
After all the above steps are in place, use the following command to build the native image:
```shell
@ -113,7 +116,7 @@ mvn -Pnative native:compile
After that, we can see the executable we generated in the ``/target`` directory.
==== Run native image
Like a normal executable file, launch this example with ``target/nacos-config-2.4.x-example``,
Like a normal executable file, launch this example with ``target/nacos-config-example``,
You can observe output similar to the following:
```shell
2022-12-22T16:28:51.006+08:00 INFO 75439 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path ''