spring boot graalvm native 试用

核心是体验下新版本支持情况同时体验下企业特性(g1 gc)

参考示例

就是基于spring start 提供的web,添加了graalvm native 构建支持,graalvm oracle 发行版直接可以官方下载

  • pom.xml 核心信息
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.1</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.dalong</groupId>
  <artifactId>graalvmappdemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>graalvmappdemo</name>
  <description>demo app</description>
  <properties>
    <java.version>17</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>native-maven-plugin</artifactId>
        <configuration>
            <buildArgs>
            <buildArg>--enable-monitoring=jfr,jmxserver,jvmstat</buildArg> // 开启了jfr 以及一些监控
            <buildArg>--gc=G1</buildArg> // 使用g1 gc 
          </buildArgs>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
 
</project>
  • 构建
    注意需要一些依赖,比如zlib 以及libstdc++-static 同时因为使用g1 gc 对于gcc 要求有点高,推荐通过centos-release-scl 构建
 
yum -y install centos-release-scl
yum install  -y devtoolset-7-gcc*
scl enable devtoolset-7 bash
mvn clean -Dmaven.test.skip package -Pnative native:build

启动&效果

  • 启动
./graalvmappdemo -XX:StartFlightRecording="filename=spring-boot.jfr" -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=xxxxx  -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=9996 -Dcom.sun.management.jmxremote.ssl=false

 

  • jmx

 

  • jfr

 

说明

默认graalvm native-image 使用的是串行gc,对于高负载场景g1 gc 会比较好,以前此功能是需要企业版的,但是最近的license 许可调整,我们可以直接使用了

参考资料

https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/
https://docs.spring.io/spring-boot/docs/3.0.0/reference/htmlsingle/#native-image

posted on   荣锋亮  阅读(239)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-06-25 数据应用访问控制的一些参考资料
2021-06-25 dremio 几个方便的命令
2020-06-25 使用coredns 的template plugin实现一个xip 服务
2020-06-25 nginx 代理 coredns dns 服务
2020-06-25 基于nginx proxy dns server
2019-06-25 flipt 一个基于golang 的特性工具开发类库
2018-06-25 graphcool-framework 一个基于graphql的后端开发框架

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示