当前位置: 首页 > news >正文

springBoot3.2 + jdk21 + GraalVM上手体验

springBoot3.2 + jdk21 + GraalVM上手体验

SpringBoot2.x官方已经停止维护了,jdk8这次真的得换了🤣
在这里插入图片描述

  • 可以参考官方文章进行体验:https://spring.io/blog/2023/09/09/all-together-now-spring-boot-3-2-graalvm-native-images-java-21-and-virtual

  • 通过官方快速得到一个基于jdk21的项目:https://start.spring.io/

快速体验(二进制部署)

@RestController
@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}@GetMapping("/customers")Collection<Customer> customers() {return Set.of(new Customer(1, "A"), new Customer(2, "B"), new Customer(3, "C"));}record Customer(Integer id, String name) {}
}

启动非常快,秒启动

image-20231201173556211

压测环境内存占用大概70MB左右,空闲时在20MB左右(由于直接打成二进制文件了,不能再使用jconsole、arthas之类的进行监控了),性能上由于不需要JVM预热,性能启动即巅峰。

$ ab -c 50 -n 10000 http://localhost:8080/customers
Server Software:
Server Hostname:        localhost
Server Port:            8080Document Path:          /customers
Document Length:        61 bytesConcurrency Level:      50
Time taken for tests:   1.413 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1660000 bytes
HTML transferred:       610000 bytes
Requests per second:    7076.39 [#/sec] (mean)
Time per request:       7.066 [ms] (mean)
Time per request:       0.141 [ms] (mean, across all concurrent requests)
Transfer rate:          1147.15 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    2   8.0      2     144
Processing:     1    5   6.7      4     147
Waiting:        0    4   5.6      3     145
Total:          1    7  10.4      6     149

image-20231201173732084

快速体验(jar部署)

jar包占用只有19MB,已经不能算是小胖jar了😊

image-20231201175815773

内存占用在压测时大概在200MB左右,空闲时在160MB左右。性能显然也不是启动即巅峰,可以看出其实还是需要进行JVM预热才能达到性能巅峰的

$ ab -c 50 -n 10000 http://localhost:8080/customers
Server Software:
Server Hostname:        localhost
Server Port:            8080Document Path:          /customers
Document Length:        61 bytesConcurrency Level:      50
Time taken for tests:   17.930 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1660000 bytes
HTML transferred:       610000 bytes
Requests per second:    557.72 [#/sec] (mean)
Time per request:       89.651 [ms] (mean)
Time per request:       1.793 [ms] (mean, across all concurrent requests)
Transfer rate:          90.41 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0   38 430.2      2    7004
Processing:     0   14  90.4      8    1773
Waiting:        0   12  88.7      6    1771
Total:          1   53 439.0     10    7011

image-20231201180038447

对比golang

package mainimport ("encoding/json""flag""fmt""net/http"
)var port = flag.String("p", "8080", "please input port")func main() {http.HandleFunc("/customers", func(writer http.ResponseWriter, request *http.Request) {data, _ := json.Marshal(request.URL)writer.Write(data)})e := make(chan error)go func() {e <- fmt.Errorf("error[%v]", http.ListenAndServe(":"+*port, nil))}()fmt.Println("http 服务器启动...")fmt.Println(<-e)
}

这里golang没有使用框架,仅使用标准库,所以内存占用较低,仅10MB左右,不过即使使用Gin之类的web框架,内存也不会超过20MB

$ ab -c 50 -n 10000 http://localhost:8080/customers
Server Software:
Server Hostname:        localhost
Server Port:            8080Document Path:          /customers
Document Length:        161 bytesConcurrency Level:      50
Time taken for tests:   1.380 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2790000 bytes
HTML transferred:       1610000 bytes
Requests per second:    7247.68 [#/sec] (mean)
Time per request:       6.899 [ms] (mean)
Time per request:       0.138 [ms] (mean, across all concurrent requests)
Transfer rate:          1974.71 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    2  16.5      2     459
Processing:     0    4  27.9      2     460
Waiting:        0    2  10.5      2     459
Total:          1    7  32.3      4     462

image-20231201174441704

结论

AOT-processed已经相对成熟,效果可以说非常惊艳,解决了JVM启动慢、需要预热、内存占用大等问题。

美中不足的是编译速度非常慢,笔者电脑是2017款mac book pro编译花费大概15分钟左右

Finished generating 'demo' in 14m 33s.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15:45 min
[INFO] Finished at: 2023-12-01T17:00:21+08:00
[INFO] ------------------------------------------------------------------------

[INFO] Total time: 15:45 min
[INFO] Finished at: 2023-12-01T17:00:21+08:00
[INFO] ------------------------------------------------------------------------


可以看出java在云原生大环境下已经取得了不错的进步的
http://www.lryc.cn/news/250490.html

相关文章:

  • Python float(input())的用法,web中的应用
  • uniapp是否可以用elementUI等前端UI库、使用步骤以及需要注意的问题
  • 在vue中如何书写 SSR 友好的代码
  • 开源与闭源:数字时代大模型之辩
  • 卷积神经网络(VGG-16)猫狗识别
  • Mysql 行转列,把逗号分隔的字段拆分成多行
  • 基于单片机设计的智能水泵控制器
  • 反转链表的实现
  • python之pyqt专栏6-信号与槽2
  • C语言中一些特殊字符的输出
  • Opencv制作电子签名(涉及知识点:像素过滤,图片通用resize函数,像素大于某个阈值则赋值为其它的像素值)
  • 【漏洞复现】大华智慧园区综合管理平台deleteFtp接口远程命令执行
  • Unity Image - 镜像
  • 深入Spring Security魔幻山谷-获取认证机制核心原理讲解(新版)
  • 【知网稳定检索】第九届社会科学与经济发展国际学术会议 (ICSSED 2024)
  • 使用Spark写入数据到数据库表
  • Codebeamer—软件全生命周期管理轻量级平台
  • Yocto - bb脚本中使用的SRC_URI、SRCREV和S
  • LeetCode | 965. 单值二叉树
  • YOLOv8创新魔改教程(一)如何进行模块创新
  • postgresql-shared_buffers参数详解
  • windows10 Arcgis pro3.0-3.1
  • Apache Airflow (十四) :Airflow分布式集群搭建及测试
  • 解决VSCode按住Ctrl(or Command) 点击鼠标左键不跳转的问题(不能Go to Definition)
  • 使用DrlParser 检测drl文件是否有错误
  • ArcGIS中基于人口数据计算人口密度的方法
  • 在CentOS 8.2中安装Percona Xtrabackup 8.0.x备份MySql
  • javascript中的正则表达式的相关知识积累
  • 51k+ Star!动画图解、一键运行的数据结构与算法教程!
  • 4.7 矩阵的转置运算(C语言实现)