行业知识
springBoot3.2 + jdk21 + GraalVM上手体验
2026-12-06 04:25:00
来源:互联网转载
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@SpringBootApplicationpublic class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}@GetMapping("/customers")Collection customers() {return Set.of(new Customer(1, "A"), new Customer(2, "B"), new Customer(3, "C"));}record Customer(Integer id, String name) {}}启动非常快,秒启动
压测环境内存占用大概70MB左右,空闲时在20MB左右(由于直接打成二进制文件了,不能再使用jconsole、arthas之类的进行监控了),性能上由于不需要JVM预热,性能启动即巅峰。
$ ab -c 50 -n 10000 http://localhost:8080/customersServer Software:Server Hostname: localhostServer Port: 8080Document Path: /customersDocument Length: 61 bytesConcurrency Level: 50Time taken for tests: 1.413 secondsComplete requests: 10000Failed requests: 0Total transferred: 1660000 bytesHTML transferred: 610000 bytesRequests 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 maxConnect: 0 2 8.0 2 144Processing: 1 5 6.7 4 147Waiting: 0 4 5.6 3 145Total: 1 7 10.4 6 149
快速体验(jar部署)
jar包占用只有19MB,已经不能算是小胖jar了
内存占用在压测时大概在200MB左右,空闲时在160MB左右。性能显然也不是启动即巅峰,可以看出其实还是需要进行JVM预热才能达到性能巅峰的
$ ab -c 50 -n 10000 http://localhost:8080/customersServer Software:Server Hostname: localhostServer Port: 8080Document Path: /customersDocument Length: 61 bytesConcurrency Level: 50Time taken for tests: 17.930 secondsComplete requests: 10000Failed requests: 0Total transferred: 1660000 bytesHTML transferred: 610000 bytesRequests 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 maxConnect: 0 38 430.2 2 7004Processing: 0 14 90.4 8 1773Waiting: 0 12 88.7 6 1771Total: 1 53 439.0 10 7011
对比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
上一篇:搭载中转服务器怎么设置?
下一篇:200元电脑装机教程