在 JVM 上启用逃逸分析的经验
我刚刚尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1 逃逸分析是否在 JConsole 中显示为已启用?您需要确保使用 -server 选项运行虚拟机。我想你已经完成了这个工作,但我只是想检查一下。
2 我不认为转义分析对 Scala Actors 的情况有帮助。如果您执行以下操作,您可能会看到很大的收获:
在上面的示例中,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:
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
来自 jdk-u18 发行说明:
from the jdk-u18 release notes:
我建议您尝试增加新生代大小,例如
-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.