简体   繁体   English

为什么堆内存使用图看起来像这样?

[英]Why does heap memory usage graph look like this?

I have install glowroot (java application monitoring) to my JVM.我已经在我的 JVM 上安装了 glowroot(java 应用程序监控)。 When my application idles, I get this kind graph formation of memory heap usage.当我的应用程序空闲时,我会得到这种内存堆使用情况图。 The pattern seems almost uniform.图案看起来几乎是统一的。 Could someone please explain and point me to whatever blog post on why does the graph looks like that?有人可以解释并指出我关于为什么图表看起来像这样的任何博客文章吗? I am curious.我好奇。

在此处输入图片说明

The large-scale sawtooth pattern represents the memory utilization between GC cycles.大规模锯齿图案表示 GC 周期之间的内存利用率。 The application is allocating objects steadily (the upsloping line) until the heap gets full enough for the VM to decide to run the GC (the point).应用程序稳定地分配对象(上坡线),直到堆满让 VM 决定运行 GC(重点)。 Then the GC reclaims a large amount of garbage (the steep drop) and the process starts again.然后 GC 回收大量垃圾(急剧下降)并重新开始该过程。

The short spikes up and down are harder to understand.向上和向下的短尖峰更难理解。 It is possible that the upward spikes represent anomalous "large" allocations (of short life-time objects) that are triggering a young generation cycle.向上的尖峰可能代表了触发年轻代周期的异常“大”分配(短生命周期对象)。 The downward spikes might represent cached objects being freed in response to "memory pressure".向下的尖峰可能表示缓存对象因“内存压力”而被释放。

If you want a better understanding of the spikes, you need to look at the GC log messages, and try to correlate them with the graphs.如果您想更好地了解峰值,您需要查看 GC 日志消息,并尝试将它们与图表相关联。

It looks like that because (at the least) you're observing it.看起来像那样是因为(至少)您正在观察它。 If your application did absolutely nothing, and there were no threads doing any allocations, you'd get a horizontal line for the heap.如果您的应用程序完全没有做任何事情,并且没有线程进行任何分配,那么您将获得一条水平线作为堆。

However since you're observing it, there are things being done in the JVM to get that data back to you.但是,由于您正在观察它,因此 JVM 中正在执行一些操作以将这些数据返回给您。 That's why you get the ubiquitous sawtooth pattern seen in many, many profiling questions.这就是为什么您会在许多分析问题中看到无处不在的锯齿图案。 A few examples below.下面举几个例子。

java memory leak, visualvm showing wrong data java内存泄漏,visualvm显示错误数据

visualvm monitors memory usage visualvm 监控内存使用情况

This is the java garbage collection at work.这是工作中的java垃圾收集。 Each drop is the garbage collector freeing memory by removing unused references.每次删除都是垃圾收集器,通过删除未使用的引用来释放内存。 The reason why it grows again is simply because your application keeps creating new references.它再次增长的原因仅仅是因为您的应用程序不断创建新的引用。

You can also have a look at this post for a more in-depth explaination: Why a sawtooth shaped graph?您还可以查看这篇文章以获得更深入的解释: 为什么是锯齿形图?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM