2024 年, graalvm native image 仍较为勉强

2024-07-14 15:26:30 +08:00
 sagaxu

果然吃内存,一个简单的 Java 程序就占用了 250M 内存

看到这个帖之后,尝试了一下把手上一个小项目做个 natvie image ,在等待了 17 分钟之后以失败告终,错误码 137(out of memory),比打传统 jar 包慢了几十倍。而同等规模的 Go 项目,构建一次比打 jar 包还快的多。

Build resources:
 - 8.31GB of memory (54.2% of 15.33GB system memory, determined at start)
 - 4 thread(s) (100.0% of 4 available processor(s), determined at start)
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
Found pending operations, continuing analysis.
[2/8] Performing analysis...  [******]                                                                 (188.0s @ 4.52GB)
   48,632 reachable types   (92.1% of   52,814 total)
   78,016 reachable fields  (64.2% of  121,484 total)
  258,776 reachable methods (60.6% of  427,364 total)
   14,060 types,   916 fields, and 13,355 methods registered for reflection
       67 types,    67 fields, and    59 methods registered for JNI access
        4 native libraries: dl, pthread, rt, z
[3/8] Building universe...                                                                              (31.3s @ 5.15GB)
[4/8] Parsing methods...      [*******]                                                                 (57.7s @ 4.01GB)
[5/8] Inlining methods...     [****]                                                                     (8.6s @ 3.48GB)
[6/8] Compiling methods...    [*************************]                                              (662.1s @ 5.38GB)

JVM 生态在云原生领域被 Go 绝对性压制的局面,十年八年之内大概不会有任何改变了。

2021 次点击
所在节点    Java
6 条回复
CodeCodeStudy
2024-07-15 10:12:34 +08:00
历史包袱太重,新的小项目玩玩还可以
karottc
2024-07-16 14:14:42 +08:00
用 quarkus 可以好一些: https://www.v2ex.com/t/1057699
sagaxu
2024-07-16 14:38:07 +08:00
@CodeCodeStudy 电脑配置低,玩也玩不动,小项目 kotlin native 也能玩。

@karottc 我用的是 vertx ,quarkus 也是在 vertx 之上封装的吧。
wssy001
2024-07-16 15:17:55 +08:00
@sagaxu 在抛弃 Hotspot 这条路上 kotlin native 做的还没 graalvm native image 好
不过这俩项目目前都不咋样
真有这方面需求 还是老老实实换语言吧
wssy001
2024-07-16 15:24:27 +08:00
以 Hotspot 为例,生产环境的主流 GC 要么 G1 要么 ZGC 但一般都选 G1 ,G1 适用场景更多。目前只有大对象大缓存应用才用 ZGC, ZGC 针对大对象分配比其他 GC 都合理并减少了性能损耗
按照 spring 团队的说法,native image 下峰值性能能达到 JIT 的 9?%(有点忘了 90%还是 95%),可以借助 PGO 进一步提升性能
(顺带说一下,Oracle GraalVM 免费了)
CodeCodeStudy
253 天前
你的那个项目是用 spring boot 吗?是什么版本? JDK 是用哪个版本?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1057196

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX