内存分析:如何检测哪个应用程序/包消耗过多内存
我在工作中遇到过这样的情况:我们运行一个 Java EE 服务器,并在其上部署了多个应用程序。最近,我们经常遇到 OutOfMemoryException。我们怀疑某些应用程序可能表现不佳,可能存在泄漏或其他问题。
问题是,我们无法真正分辨出是哪一个。我们运行了一些内存分析器(例如 YourKit),它们非常擅长告诉哪些类使用最多的内存。但它们没有显示类之间的关系,因此这给我们留下了这样的情况:我们看到有很多字符串、int 数组和 HashMap 条目,但我们无法真正分辨出它们是哪个应用程序或包来自。
有没有办法知道这些对象来自哪里,以便我们可以尝试查明分配最多内存的包(或应用程序)?
I have a situation here at work where we run a Java EE server with several applications deployed on it. Lately, we've been having frequent OutOfMemoryException's. We suspect some of the apps might be behaving badly, maybe leaking, or something.
The problem is, we can't really tell which one. We have run some memory profilers (like YourKit), and they're pretty good at telling what classes use the most memory. But they don't show relationships between classes, so that leaves us with a situation like this: We see that there are, say, lots of Strings and int arrays and HashMap entries, but we can't really tell which application or package they come from.
Is there a way of knowing where these objects come from, so we can try to pinpoint the packages (or apps) that are allocating the most memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,可以执行以下操作:
There are several things that one could do in this situation:
一个快速的想法是,如果您不介意进行一些性能权衡,您可能可以进行一些反思......
A quick thought is that you probably can do some reflection, if you don't mind some performance trade-off....
我发现有用的是:(
删除 32 位架构的
-J-d64
选项)这将输出如下内容:
然后从那里您可以尝试进一步诊断问题,进行差异以及不应该比较连续快照的内容。
这只会使虚拟机暂停一小段时间,即使是大堆,因此您可以在生产中安全地执行此操作(希望在非高峰时段:))
What I have found helpful is:
(remove the
-J-d64
option for 32-bit arch)This will output something like this:
And then from there you can try to further diagnose the problem, doing diffs and what not to compare successive snapshots.
This will only pause the VM for a brief time, even for big heaps, so you can safely do this in production (during off-peak hours, hopefully :) )