简体   繁体   English

Java垃圾收集:次要,主要,完整

[英]Java garbage collection: minor, major, full

I am trying to get a hang on garbage collection in a large enterprise Java application. 我试图在大型企业Java应用程序中挂起垃圾收集。 I have the GC logs and started looking into them using various tools - the screenshot here is done using GCViewer . 我有GC日志并开始使用各种工具查看它们 - 这里的截图是使用GCViewer完成的。 (Sadly there is no logs with more verbose GC info...) (遗憾的是,没有更详细的GC信息的日志...)

I was also reading up on the Java Hotspot VM garbage collection, which we are using. 我还在阅读我们正在使用的Java Hotspot VM垃圾收集。

But I am still somewhat confused: below is a screenshot of a zoomed in section of the GC graph. 但我仍然有些困惑:下面是GC图表放大部分的屏幕截图。

放大垃圾收集图

There are three things going on here: 这里有三件事:

  1. There is the "small zigzag" of the blue line (which you can hardly see): from what I understand these are minor gc cycles happing in Young space. 蓝线的“小曲折”(你几乎看不到):据我所知,这些是年轻空间中的 gc周期。
  2. There is the black bar, which is a blocking 10s full GC, as can be seen in the logs: 有一个黑条,这是一个阻塞10s全GC,可以在日志中看到:

     1751585.394: [Full GC 1433326K->660045K(1552832K), 10.1157600 secs] 
  3. Then there is the "big zigzag" of the blue line (manifesting in the drop on the left). 然后是蓝线的“大曲折”(在左边的水滴中显示)。 This is what confuses me. 这让我很困惑。

The logs for pattern #3 don't mark it as full GC, but look similar to the rest... 模式#3的日志不会将其标记为完整GC,但看起来与其他类似...

    1749795.648: [GC 1299871K(1552832K), 0.0402933 secs]
  • So is this a minor GC as well? 这也是一个次要GC吗?
  • If yes, why are there two different patterns of minor garbage collects happening at the same time (#1 and #3)? 如果是,为什么同时发生两种不同的小型垃圾收集模式(#1和#3)?
  • Or is there something else between minor GC in Young space and full GC in Tenured? 或者Young空间中的小GC和Tenured中的完整GC之间还有其他什么?

Edit. 编辑。 Some additional info: 一些额外的信息:
GC used: Concurrent Mark-Sweep GC GC使用:并发Mark-Sweep GC
Throughput is 93.8 % 吞吐量为93.8%
Longest Pause: 10.116 seconds 最长暂停:10.116秒
Time Paused: 6.21% 暂停时间:6.21%

Java's generational garbage collector has several different "kinds" of garbage collection. Java的世代垃圾收集器有几种不同的“种类”的垃圾收集。 As you mentioned, the "small zig-zags" are minor collections in the young space, and the black bar would be a full garbage collection. 正如你所提到的,“小zig-zags”是年轻空间中的小型收藏品,黑色条形图将是一个完整的垃圾收集。 For the sake of simplicity, I'll just describe the most important parts of what's happening. 为简单起见,我将描述正在发生的事情中最重要的部分。

The young generation is divided into an "Eden" space one or more "survivor" spaces. 年轻一代被划分为“伊甸园”空间一个或多个“幸存者”空间。 During one of those small zig-zags, dead objects in the Eden space are removed, and live objects are moved to one of the survivor spaces. 在其中一个小的锯齿形中,伊甸园空间中的死亡物体被移除,活体物体被移动到一个幸存者空间。 This is a very quick operation, because the weak generational hypothesis states that most objects will be short-lived. 这是一个非常快速的操作,因为世代假设指出大多数对象将是短暂的。 A subsequent sweep of the survivor space may move objects that are still alive from the survivor space into the tenured generation. 幸存者空间的后续扫描可以移动仍旧活动从生存空间到年老代的对象。 This is still considered a minor collection. 这仍然被认为是次要的集合。

I suspect what you see in the first big drop is actually a "promotion" from the survivor generations to the tenured generation. 我怀疑你在第一次大跌中所看到的实际上是从幸存者一代到终身一代的“晋升”。

The tenured generation is everything that is not young enough to be in the young generation (what this means, like many other GC options, is tuneable). 终身一代是年轻一代不够年轻的一切(这意味着像其他许多GC选项一样可调)。 The tenured generation is much larger than the young generation, and therefore takes a lot of time to sweep. 终生代比年轻一代大得多,因此需要花费大量时间来扫除。 When you talk about a "full" garbage collection, this refers to a sweep of the tenured generation (in addition to the young generation). 当你谈到一个“完整的”垃圾收集时,这指的是对终生代的扫描(除了年轻一代)。

The CMS garbage collector operates concurrently for most of the things it does, but still needs to stop the world for the mark operations on the young and tenured generations. CMS垃圾收集器在其执行的大部分操作中同时运行,但仍需要停止世界,以便在年轻和终身的世代中进行标记操作。 The CMS collector is supposed to be very quick at this, even for large heaps. CMS收集器应该非常快,即使对于大堆也是如此。 However, there's one other situation where CMS stops the world: concurrent mode failure . 但是,还有一种情况是CMS阻止了这个世界: 并发模式失败

The second big drop with the pause may have been a result of this, which occurs when the tenured generation is too full. 暂停的第二次大幅下降可能是由于这种情况造成的,这种情况发生在终身发电过剩时。 You can adjust the size of the tenured generation and other parameters to avoid these. 您可以调整tenured generation和其他参数的大小以避免这些。

I doubt this is a concurrent-sweep. 我怀疑这是一个并发扫描。 To confirm, must monitor with following 要确认,必须跟踪以下

-verbose:gc -XX:+PrintGCDetails

And assuming the graph is showing young + tenured generation, this cannot be a promotion from the survivor generations to the tenured generation as Jonathan has mentioned. 并且假设图表显示年轻+终身一代,这不能像Jonathan所提到的那样从幸存者世代升到终身一代。

Based on the logs you have, I would say: 根据您的日志,我会说:

1) this is a minor collection. 1)这是一个小集合。 As @Eugene says above, it is short and it is not labelled as a full-gc. 正如@Eugene上面所说,它很短,并没有被标记为完整的gc。

2) there are two sorts of short-lived objects in your application at this point. 2)此时应用程序中有两种短期对象。 Some very short-lived ones which "last" the amount of time between 2 of those small zigzags. 一些非常短命的“持续”在这些小曲折中的两个之间的时间量。 And some longer-lived ones, which still do not last long enough to be promoted to the tenured generation, and which become eligible for gabage-collection at some point before the confusing minor-collection. 而一些寿命较长的,仍然没有足够长的时间被提升为终身一代,并且在混乱的小集合之前的某个时刻有资格收集垃圾。

There may be other explanation but I don't believe you can tell that from what you have. 可能还有其他解释,但我不相信你可以从你拥有的东西中辨别出来。

If you are concerned by it (or maybe if you are just curious) I would enable more detailed gc logging, and use logs like your access-logs to try and correlate application activity with the drop. 如果您担心它(或者如果您只是好奇的话),我会启用更详细的gc日志记录,并使用访问日志之类的日志来尝试将应用程序活动与drop相关联。

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

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