如何在Java中分析内存碎片? [英] How to analyze memory fragmentation in java?

查看:260
本文介绍了如何在Java中分析内存碎片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在服务器中遇到了几分钟的延迟.它们可能是由阻止世界"垃圾收集触发的.但是我们使用并发标记和清除GC(-XX:+ UseConcMarkSweepG),因此,我认为,这些暂停是由旧一代的内存碎片触发的.

We experience several minutes lags in our server. Probably they are triggered by "stop the world" garbage collections. But we use concurrent mark and sweep GC (-XX:+UseConcMarkSweepG) so, I think, these pauses are triggered by memory fragmentation of old generation.

如何分析老一代的内存碎片?有什么工具吗?

How can memory fragmentation of old generation be analyzed? Are there any tools for it?

每小时都会发生延迟.大多数时间是20秒左右,但有时是几分钟.

Lags happen every hour. Most time they are about 20 sec, but sometimes - several minutes.

推荐答案

在Java文档中查找用于打开GC日志记录的"java -X ..."选项.这样可以告诉您是要收集旧的还是新一代的,以及收集需要多长时间.

Look at your Java documentation for the "java -X..." options for turning on GC logging. That will tell you whether you are collecting old or new generation, and how long the collections are taking.

几分钟"的停顿听起来很不正常.您确定不只是在堆大小过小的情况下运行,还是在物理内存不足的计算机上运行?

A pause of "several minutes" sounds extraordinary. Are you sure that you aren't just running with a heap size that is too small, or on a machine with not enough physical memory?

  • 如果堆太接近满了, GC将再次被触发, 再次,导致您的服务器 将大部分的CPU时间都花在 GC.这将显示在GC中 日志.

  • If your heap too close to full, the GC will be triggered again and again, resulting in your server spending most of its CPU time in the GC. This will show up in the GC logs.

如果在计算机上使用大堆 没有足够的物理内存, 完整的GC可能会导致 您的机器崩溃",花费 大部分时间疯狂地移动虚拟 光盘上的内存页面.你 可以使用系统观察 监控工具;例如通过观看 从"vmstat 5"上的控制台输出 典型的UNIX/Linux系统.

If you use a large heap on a machine with not enough physical memory, a full GC is liable to cause your machine to "thrash", spending most of its time madly moving virtual memory pages to and from disc. You can observe this using system monitoring tools; e.g. by watching the console output from "vmstat 5" on a typical UNIX/Linux system.

关注

与OP的看法相反,打开不太可能,从而对性能产生明显的影响.

Contrary to the OP's belief, turning on GC logging is unlikely to make a noticeable difference to performance.

了解并发标记扫描垃圾收集器日志的页面 Oracle站点应有助于解释GC日志.

The Understanding Concurrent Mark Sweep Garbage Collector Logs page on the Oracle site should be helpful in interpreting GC logs.

最后,OP不太可能得出这是碎片化"问题的结论,并且(IMO)没有得到他提供的证据片段的支持.很有可能是其他东西.

Finally, the OP's conclusion that this is a "fragmentation" problem is unlikely, and (IMO) unsupported by the snippets of evidence that he has provided. It is most likely something else.

这篇关于如何在Java中分析内存碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆