什么时候不使用G1GC垃圾收集器?

发布于 2025-01-30 05:49:08 字数 346 浏览 2 评论 0 原文

我研究了可用于JVM的各种垃圾收集器之间的差异。 是解释它们之间主要区别的答案: https://stackoverflow.com/a/54619838/54619838/5345646

这 为G1GC说:

它是低暂停 /服务器样式GC,主要用于大堆(&gt; 4GB)。< / p>

我们有一台机器的总内存为4 GB,并且分配给JVM的堆尺寸为1 GB。我想了解这是否会给我们带来任何问题,还是G1GC可以奏效。

I looked into differences between various garbage collectors available for JVM. Here is the answer explaining the main differences between them : https://stackoverflow.com/a/54619838/5345646

Here it's said for G1GC that :

It's low pause / server style gc, mainly for large heap (> 4Gb).

We have a machine that has a total memory of 4 GB, and heap size allocated to JVM of 1 GB. I wanted to understand whether that would cause any issues for us, or would G1GC work out fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Smile简单爱 2025-02-06 05:49:08

以下摘要基于:


  • 如果您对GC停顿时间绝对没有兴趣,请使用串行收集器(如果您只有一个核心)或并行收集器(如果您有一个以上的核心)。

  • 如果您需要低暂停时间(概率很高),则使用G1收集器。

  • 如果您需要超低的停顿时间,并且/或者您的堆非常大,请使用z收集器。

从Java 14开始,旧的CMS收集器已被删除。


请注意,如果您指定暂停时间和/或吞吐量目标,则可以将GC的选择和调整放在JVM上。当您不了解自己在做什么时,这可能比手动选择和调整GC的风险要小。

描述了这种“基于行为的调谐”方法及其优势在这里


您问:

我们有一台机器的总内存为4 GB,并且分配给JVM的堆大小为1 GB。我想了解这是否会给我们带来任何问题,还是G1GC可以很好地工作。

我们无法告诉您是否可以正常工作。这将取决于应用程序行为的各个方面以及您的期望。例如,如果您的应用程序遇到了这些问题,那么“问题”会涉及您。我建议尝试“基于行为的调谐”,然后看看那些带您的地方。

最后,设置最大的堆大小太小,无法用于应用程序,无论您选择什么GC,都不会结束 ...。

The following summary is based on:


  • If you have absolutely no interest in GC pause times, then use the serial collector (if you only have one core) or the parallel collector (if you have more than one core).

  • If you need low pause times (with high probability), then use the G1 collector.

  • If you need ultra-low pause times, and/or you have an extremely large heap, use the Z collector.

The old CMS collector has been removed as of Java 14.


Note that if you specify pause-time and/or throughput goals, you can leave the choice and tuning of the GC to the JVM. This is probably less risky than manually selecting and tuning the GC ... when you don't understand what you are doing.

This "behavior-based tuning" approach and its advantages are described here.


You asked:

We have a machine that has a total memory of 4 GB, and heap size allocated to JVM of 1 GB. I wanted to understand whether that would cause any issues for us, or would G1GC work out fine.

We can't tell you whether it would work out fine or not. It would depend on various aspects of your application's behavior and also on your expectations. For example, what "issues" would concern you if your application encountered them. I would recommend trying "behavior-based tuning" to start with, and see where that gets you.

Finally, setting a maximum heap size that is too small for the application will not end well ... no matter what GC you select.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文