Java 什么设置JVM参数MaxNewSize的值?人体工学?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22455562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:49:20  来源:igfitidea点击:

What set the value of JVM parameter MaxNewSize? Ergonomics?

javajvmcentos6ergonomics

提问by user2692131

My server info:

我的服务器信息:

  • CPU:Intel Xeon E5-2630
  • Memory:65970676K
  • OS:Centos 6.4
  • kernel:3.8.0
  • jdk: HotSpot JDK 1.6.0.27
  • CPU:英特尔至强 E5-2630
  • 内存:65970676K
  • 操作系统:Centos 6.4
  • 内核:3.8.0
  • jdk:热点 JDK 1.6.0.27

I use jmap -heap pidto print heap info:

jmap -heap pid用来打印堆信息:

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize      = 21474836480 (20480.0MB)
NewSize          = 21757952 (20.75MB)
MaxNewSize       = 174456832 
OldSize          = 65404928 (62.375MB)
NewRatio         = 7
 SurvivorRatio    = 8
PermSize         = 268435456 (256.0MB)
MaxPermSize      = 268435456 (256.0MB)

And following are the JVM args I defined to run my application:

以下是我为运行应用程序而定义的 JVM 参数:

 -verbose:gc  -XX:+UseMembar -XX:+PrintGCDetails - 
 XX:+PrintGCTimeStamps  -XX:+DisableExplicitGC - 
 XX:+CMSClassUnloadingEnabled
-XX:-OmitStackTraceInFastThrow  -Xloggc:/export/logs/gc.log 
-XX:PermSize=256m -XX:MaxPermSize=256m -Xms6G  -Xmx12G

I don't set MaxNewSize, I tried to use java -XX:+PrintFlagsFinalto print all of the JVM args and found MaxNewSizeis a very very big number: 18446744073709486080. I think Ergonomics may have set MaxNewSizeto 174456832for me. However, I have another server, which has the same hardware and software, where MaxNewSizeis 392560640while other heap parameters are the same.

我没有设置MaxNewSize,我尝试使用java -XX:+PrintFlagsFinal打印所有 JVM 参数,发现MaxNewSize是一个非常大的数字:18446744073709486080。我认为人体工程学可能已经为我MaxNewSize准备174456832好了。不过,我还有一个服务器,它具有相同的硬件和软件,其中MaxNewSize392560640而其他堆参数是相同的。

What's the basis for Ergonomics setting the value of MaxNewSize? Can I see this in the source code of Ergonomics?

人体工程学设定 值的依据是MaxNewSize什么?我可以在 Ergonomics 的源代码中看到这个吗?

I think I found where the value of MaxNewSize is set:Arguments.cpp (hotspot\src\share\vm\runtime)

我想我找到了 MaxNewSize 的值在哪里设置:Arguments.cpp (hotspot\src\share\vm\runtime)

if (CMSUseOldDefaults) {  // old defaults: "old" as of 6.0
  if FLAG_IS_DEFAULT(CMSYoungGenPerWorker) {
    FLAG_SET_ERGO(intx, CMSYoungGenPerWorker, 4*M);
  }
  young_gen_per_worker = 4*M;
  new_ratio = (intx)15;
  min_new_default = 4*M;
  tenuring_default = (intx)0;
} else { 
  // new defaults: "new" as of 6.0
  young_gen_per_worker = CMSYoungGenPerWorker;
  new_ratio = (intx)7;
  min_new_default = 16*M;
  tenuring_default = (intx)4;
}

// Preferred young gen size for "short" pauses
const uintx parallel_gc_threads =
(ParallelGCThreads == 0 ? 1 : ParallelGCThreads);

 const size_t preferred_max_new_size_unaligned =
    ScaleForWordSize(young_gen_per_worker * parallel_gc_threads);
  const size_t preferred_max_new_size =
align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());

回答by AR5HAM

In JDK 5, a new performance feature for self tuning of the JVM known as JVM Ergonomics was added. This is also in JDK 6. The idea is that when the java process gets started, it can examine the underlying system resources and determine some of the tuning parameters automatically in the case certain options are not set. In other words, it is trying to provide a good performance from the JVM with a minimum of command line tuning.

在 JDK 5 中,添加了一项新的性能特性,用于自调整 JVM,称为 JVM Ergonomics。这在JDK 6中也是如此。这个想法是当java进程启动时,它可以检查底层系统资源并在某些选项没有设置的情况下自动确定一些调整参数。换句话说,它试图通过最少的命令行调整从 JVM 中提供良好的性能。

Generation:Beginning with the J2SE Platform version 1.2, the virtual machine incorporated a number of different garbage collection algorithms that are combined using generational collection. While naive garbage collection examines every live object in the heap, generational collection exploits several empirically observed properties of most applications to avoid extra work.

生成:从 J2SE 平台 1.2 版开始,虚拟机合并了许多不同的垃圾收集算法,这些算法使用分代收集进行组合。虽然朴素的垃圾收集检查堆中的每个活动对象,但分代收集利用大多数应用程序的几个经验观察属性来避免额外的工作。

Sizing GenerationA number of parameters affect generation size. At initialization of the virtual machine, the entire space for the heap is reserved. The size of the space reserved can be specified with the -Xmx option. If the value of the -Xms parameter is smaller than the value of the -Xmx parameter, not all of the space that is reserved is immediately committed to the virtual machine. The uncommitted space is labeled "virtual". The different parts of the heap ( permanent generation, tenured generation, and young generation) can grow to the limit of the virtual space as needed.

调整代数许多参数会影响代的大小。在虚拟机初始化时,为堆保留了整个空间。保留空间的大小可以使用 -Xmx 选项指定。如果 -Xms 参数的值小于 -Xmx 参数的值,则并非所有保留的空间都会立即提交给虚拟机。未提交的空间被标记为“虚拟”。堆的不同部分(永久代、老年代和年轻代)可以根据需要增长到虚拟空间的极限。

Some of the parameters are ratios of one part of the heap to another. For example the parameter NewRatiodenotes the relative size of the tenured generation to the young generation.

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

Young GenerationThe second most influential knob is the proportion of the heap dedicated to the young generation. The bigger the young generation, the less often minor collections occur. However, for a bounded heap size a larger young generation implies a smaller tenured generation, which will increase the frequency of major collections. The optimal choice depends on the lifetime distribution of the objects allocated by the application.

年轻代第二个最有影响的旋钮是分配给年轻代的堆的比例。年轻代越大,小回收发生的频率就越低。然而,对于有界堆大小,较大的年轻代意味着较小的年老代,这将增加主要收集的频率。最佳选择取决于应用程序分配的对象的生命周期分布。

By default, the young generation size is controlled by NewRatio. For example, setting -XX:NewRatio=3 means that the ratio between the young and tenured generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one fourth of the total heap size.

默认情况下,新生代大小由 NewRatio 控制。比如设置-XX:NewRatio=3,表示年轻代和年老代的比例为1:3。换句话说,伊甸园和幸存者空间的总大小将是总堆大小的四分之一。

The parameters NewSizeand MaxNewSizebound the young generation size from below and above. Setting these equal to one another fixes the young generation, just as setting -Xms and -Xmx equal fixes the total heap size. This is useful for tuning the young generation at a finer granularity than the integral multiples allowed by NewRatio.

参数NewSizeMaxNewSize从下到上限制了年轻代的大小。将这些设置为彼此相等可以修复年轻代,就像将 -Xms 和 -Xmx 设置为相等可以修复总堆大小一样。这对于以比 NewRatio 允许的整数倍更细的粒度调整年轻代很有用。

If you need more info on this topic here are couple of useful links:

如果您需要有关此主题的更多信息,这里有几个有用的链接: