gpt4 book ai didi

java - 使用并发标记扫描 GC 收集器?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:17:49 26 4
gpt4 key购买 nike

这个问题是基于我对 link 的 Java 垃圾收集器部分的理解看起来 jvm 默认情况下在 Windows 7 上使用“Parallel GC”,正如我确认的那样 -XX:+PrintCommandLineFlags -version。这篇文章还说

The parallel garbage collector uses multiple threads to perform the young generation garbage collection. This collector should be used when a lot of work need to be done and long pauses are acceptable

我不确定并行 GC 使用哪个收集器来收集永久空间?

我也想不出可以接受长时间停顿的应用程序(会导致响应速度降低)。任何人都希望减少 GC 的暂停时间并使应用尽可能地响应。

然后我阅读了Concurrent Mark Sweep (CMS) Collector,它收集了tenured generation

CMS 表示它需要低暂停时间并且可以与垃圾回收共享资源

我的问题是最不应该的 Web 应用程序使用 Concurrent Mark Sweep (CMS) Collector 是因为它的响应能力。?决定,但在通过此链接后,我觉得我应该将默认 GC 类型更改为并发标记扫描 (CMS) 收集器。有什么想法/见解吗?

此外,我认为如果我们同时使用 CMS 收集器和并行收集器,应用程序可能是最好的,其中 CMS 用于老年代和并行 fpr年轻一代

最佳答案

i am not sure which collector is used for tenured space collection by Parallel GC?

离开this页面,如果你使用并行 GC,则并行清除收集器用于年轻代,并行标记/清除收集器用于老年代(也称为老一代)。所以我猜答案是“Parallel GC 用于 Parallel GC 的永久空间收集”。有点循环陈述,但我认为这是有道理的。

Also i could not think of applications where long pauses are acceptable(will cause less responsiveness). Anyone would like to less pauses for GC and make app as responsive as it can.

“长时间停顿”是相对的,是否可以接受取决于应用程序的类型及其用途。需要快速用户交互的应用程序(例如游戏)可能需要较短的暂停时间,而长时间运行的应用程序几乎没有用户交互(通宵批处理作业、可以运行几天的处理作业、可能运行很长时间的服务器)时间段等),或者不需要快速用户交互(文字处理器?但是谁用 Java 编写文字处理器?)几乎没有严格的暂停要求,所以暂停是好的那些。此外,暂停不是唯一要考虑的 GC 因素,因此即使暂停是可以的,也有其他原因会选择暂停时间较长的 GC。我会在下面进一步解释。

My question is should not most of web applications use Concurrent Mark Sweep (CMS) Collector because of its responsiveness.?

CMS 收集器有缺点。在你提到的文章中,有这一行:

Normally the concurrent low pause collector does not copy or compact the live objects. A garbage collection is done without moving the live objects.

所以没有堆压缩会导致堆碎片,这可能对性能有害。 This帖子指出了另一个缺点(我不确定这篇帖子到底有多可靠,但乍一看似乎相当不错):

A more important disadvantage of the CMS collector is related to the fact that it cannot be started when the Old generation heap is full. Once the Old generation is full, it is too late for the CMS and it must then fall back to the usual stop-the-world strategy (announced by a “concurrent mode failure” in the GC log).

...

The biggest disadvantage of the CMS, however, is related to the fact that it does not compact the Old generation heap. It therefore carries the risk of heap fragmentation and severe operations degradation over time.

...

It is obvious that with these settings the JVM worked well for almost 14 hours under loadtest conditions (in production and with lower load this treacherously benign period may last much longer). Then suddenly there were very long GC pauses which actually stopped the JVM for about half of the remaining time. There were not only attempts to clean up the mess in the Old generation which lasted more than 10 seconds but even New generation GC pauses were in the seconds range because the collector spent a lot of time searching for space in the Old generation when it tried to promote objects from new to Old generation.

博文中有更多详细信息,您可能应该阅读这些内容,因为这里的引述之外还有很多内容以及一些精彩的演示。但要指出的是,CMS 收集器并不是一个通用的收集器。它也有它的缺点,这可能会导致程序员选择不同的收集器。对于短时间运行的应用程序,将它用作默认值可能没问题,但对于长时间运行的应用程序,这种行为将非常糟糕...

Further i think application can be best if we use CMS Collector and parallel collector together where CMS is used for old generation and parallel fpr younger generation

当您将 -XX:+UseConcMarkSweepGC 参数传递给您的 VM 时,这实际上是默认模式。但如上所述,您可能真的需要花一些时间来考虑要使用哪种收集器。在不考虑您的用例的情况下选择收集器可能不是一个好主意。 (旁注:我以为我从 Oracle 看到了一些关于如何决定使用什么 GC 的文档,但我再也找不到了...)

此外,如果您有 Java 7u4 或更高版本,您可能需要考虑 Shiny 的新 G1 收集器。它应该是 CMS 收集器的替代品。

关于java - 使用并发标记扫描 GC 收集器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24593300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com