JVM GC 官方调优文档翻译

官方资料

1、JVM官方介绍
2、JVM linux macOS 参数文档
3、官方gc调优指南

GC 官方调优

许多参数会影响生成大小。“堆参数”说明了堆中提交空间和虚拟空间的区别。在虚拟机初始化时,堆的整个空间都被保留。保留空间的大小可以使用-Xmx选项指定。如果-Xms参数的值小于-Xmx参数的值,那么并不是所有保留的空间都立即提交给虚拟机。未提交的空间在该图中标记为“virtual”。堆的不同部分(终身生成)

有些参数是堆的一部分与另一部分的比率。例如,参数NewRatio表示成年代与年轻代的相对大小。

1、影响垃圾收集性能的最重要因素是可用内存总量。因为GC发生在代满时,所以吞吐量与可用内存量成反比。

参数 默认值 含义
MinHeapFreeRatio 40 最小空闲堆比例
MaxHeapFreeRatio 70 最大空闲堆比例
-Xms 6656k 初始化堆大小
-Xmx 估算 最大堆大小

2、在可用内存总量之后,影响垃圾收集性能的第二大影响因素是专用于年轻代的堆的比例。年轻代越大, minor collections发生的频率就越低。然而,对于有限的堆大小,更大的年轻代意味着更小的长期代,这将增加 major collections 的频率。最佳选择取决于应用程序分配的对象的生存期分布。

参数 默认值 含义
NewRatio 2 young : tenured = 1:2 新生代占总堆的 三分之一
NewSize 1310M young 的默认大小
MaxNewSize 无限制 最大年轻代内存
SurvivorRatio 8 eden 与 survivor 的比例

可以使用参数SurvivorRatio来调优幸存者空间的大小,但这对于性能通常并不重要。例如,-XX:SurvivorRatio=8将eden和Survivor之间的比率设置为1:8。换句话说,每个Survivor的大小将是eden的八分之一,因此是年轻一代的十分之一(不是九分之一,因为有两个幸存者空间)。

If survivor spaces are too small, copying collection overflows directly into the tenured generation. If survivor spaces are too large, they will be uselessly empty. At each garbage collection, the virtual machine chooses a threshold number, which is the number times an object can be copied before it is tenured. This threshold is chosen to keep the survivors half full. The command line option -XX:+PrintTenuringDistribution (not available on all garbage collectors) can be used to show this threshold and the ages of objects in the new generation. It is also useful for observing the lifetime distribution of an application.

如果survivor 太小,则复制GC会直接溢出到 tenured 代。如果survivor 太大,就会变成无用的空空间。在每次垃圾回收时,虚拟机选择一个阈值数,这个阈值是一个对象在放入tenured代之前可以复制的次数。选择此阈值是为了使survivor 保持一半满。命令行选项 -XX:+PrintTenuringDistribution(不是在所有垃圾收集器上都可用)可以用来显示这个阈值和新一代对象的年龄。它对于观察应用程序的生存期分布也很有用。

 -XX:+PrintTenuringDistribution

The following are general guidelines for server applications:

  • First decide the maximum heap size you can afford to give the virtual machine. Then plot your performance metric against young generation sizes to find the best setting.

    • Note that the maximum heap size should always be smaller than the amount of memory installed on the machine to avoid excessive page faults and thrashing.
  • If the total heap size is fixed, then increasing the young generation size requires reducing the tenured generation size. Keep the tenured generation large enough to hold all the live data used by the application at any given time, plus some amount of slack space (10 to 20% or more).

  • Subject to the previously stated constraint on the tenured generation:

    • Grant plenty of memory to the young generation.

    • Increase the young generation size as you increase the number of processors, because allocation can be parallelized.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • GC和GC Tuning GC的基础知识 1.什么是垃圾 C语言申请内存:malloc freeC++: new ...
    我_976b阅读 583评论 0 0
  • GC和GC Tuning 原作者:马士兵老师http://mashibing.com GC的基础知识 1.什么是垃...
    fat32jin阅读 1,013评论 0 0
  • GC和GC Tuning GC的基础知识 1.什么是垃圾 C语言申请内存:malloc freeC++: new ...
    Coding测试阅读 1,125评论 0 9
  • 1.一些概念 1.1.数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型。基本类型的变量保存原始...
    落落落落大大方方阅读 4,806评论 4 86
  • 调优设置具体解析 一.堆大小设置 JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-b...
    魏宁_david阅读 425评论 0 0

友情链接更多精彩内容