在 JVM 上启用逃逸分析的经验

发布于 2024-08-20 14:15:54 字数 596 浏览 7 评论 0原文

我刚刚尝试在 jdk6-u18 VM(在Solaris 上)上启用-XX:+DoEscapeAnalysis 选项,但体验相当令人失望。我正在运行一个 scala 应用程序,它有很多参与者(其中 20,000 个)。这是制造垃圾的秘诀!

通常,应用程序可以使用 256Mb 的堆运行,但会生成大量垃圾。在其稳定状态中:

  • 花费 10% 的时间进行 GC
  • ,在 30 秒内生成 >150Mb 的垃圾,然后进行 GC

我认为逃逸分析可能会有所帮助,因此我启用了该选项并重新-运行应用程序。我发现应用程序变得越来越无法清除它收集的垃圾,直到它似乎最终将整个时间都花在 GC 上,并且应用程序在其完全分配时“趋于平稳”。

此时我应该说应用程序没有抛出我所期望的 OutOfMemoryError 。也许JConsole(我用来执行分析的)在打开此选项时无法正确显示 GC 统计信息(我不相信)?

然后我删除了该选项并重新启动,应用程序再次变得“正常”!有人知道会发生什么吗?

I've just tried the -XX:+DoEscapeAnalysis option enabled on a jdk6-u18 VM (on solaris) and had a rather disappointing experience. I'm running a scala application which has rather a lot of actors (20,000 of them). This is a recipe for garbage-creation!

Typically the app can run with 256Mb of heap but generates huge amounts of garbage. In its steady state it:

  • spends 10% of time in GC
  • generates >150Mb of garbage in <30s which then gets GC'd

I thought that escape analysis might help so I enabled the option and re-ran the app. I found that the app became increasingly unable to clear away the garbage it had collected until it seemed eventually to spend the entire time doing GC and the app was "flatlining" at its full allocation.

At this point I should say that the app did not throw a OutOfMemoryError which I would have expected. Perhaps JConsole (which I was using to perform the analysis) does not properly display GC stats with this option on (I'm not convinced)?

I then removed the option and restarted and the app became "normal" again! Anyone have any idea what might be going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

1 逃逸分析是否在 JConsole 中显示为已启用?您需要确保使用 -server 选项运行虚拟机。我想你已经完成了这个工作,但我只是想检查一下。

2 我不认为转义分析对 Scala Actors 的情况有帮助。如果您执行以下操作,您可能会看到很大的收获:

def act():Unit = {
   val omgHugeObject = new OMGHugeObject();
   omgHugeObject.doSomethingCrazy();
 }

在上面的示例中,EscapeAnalysis 将使 omgHugeObject 可以分配在堆栈而不是堆上,从而不会创建垃圾。我认为逃逸分析不太可能对演员有帮助。他们的引用总是会“逃逸”到参与者子系统。

3
您使用的是最新版本的 Scala 吗?有一个内存泄漏,我相信在最近的版本中已修复。这甚至导致 Lift 产生您可能会查看的自己的 Actor 库。

4 您可以尝试使用 G1Garbage 收集器,您可以通过以下方式启用它:

-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC

1 Did the escape analysis show up as being enabled in JConsole? You need make sure you're running the VM with the -server option. I assume you had this working, but I just thought I'd check.

2 I don't think escape analysis will help the situation with Scala Actors. You might see a big gain if you do something like:

def act():Unit = {
   val omgHugeObject = new OMGHugeObject();
   omgHugeObject.doSomethingCrazy();
 }

In the example above the EscapeAnalysis would make it so omgHugeObject could be allocated on the stack instead of the heap and thus not create garbage. I don't think it is likely that the escape analysis will help with actors. Their references will always "escape" to the actor subsystem.

3
Are you on the most recent release of Scala? There was a memory leak that I believe was fixed in a recent version. This even caused Lift to spawn off its own Actor library that you might look into.

4 You might try the G1Garbage collector You can enable it with:

-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC

萌逼全场 2024-08-27 14:15:54

来自 jdk-u18 发行说明

请注意,基于转义分析的优化 (-XX:+DoEscapeAnalysis) 在 6u18 中被禁用。此选项将在未来的 Java SE 6 更新中恢复。

from the jdk-u18 release notes:

Note that Escape analysis-based optimization (-XX:+DoEscapeAnalysis) is disabled in 6u18. This option will be restored in a future Java SE 6 update.

七秒鱼° 2024-08-27 14:15:54

我建议您尝试增加新生代大小,例如-XX:NewSize=96M XX:NewRatio=3。使用 JVisualVM(包含在 JDK 中)和 Visual GC 插件来观察如何年轻人和老年人的空间都得到利用。

I suggest you try to increase the new generation size, e.g. -XX:NewSize=96M XX:NewRatio=3. Use JVisualVM (included in the JDK), with the Visual GC Plugin to watch how the young and old spaces are utilised.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文