Garbage Collector Ergonomics

Garbage Collector Ergonomics
垃圾收集策略
Note: For Java SE 8 and later, see Java HotSpot Virtual Machine Garbage Collection Tuning Guide.
注意:对于JavaSE8和更高版本,请参阅JavaHotspot虚拟机垃圾收集优化指南。
The following changes take effect with Java SE 5.0.
以下更改在JavaSE5.0中生效。
Garbage Collector of Server VM Changed to Parallel Garbage Collector
On server-class machines running the server VM, the garbage collector (GC) has changed from the previous serial collector (-XX:+UseSerialGC) to a parallel collector (-XX:+UseParallelGC). You can override this default by using the -XX:+UseSerialGC command-line option to the java command.
服务器虚拟机的垃圾收集器已更改为并行垃圾收集器

在运行服务器虚拟机的服务器类计算机上,垃圾收集器(GC)已从以前的串行收集器(-XX:+UseSerialGC)更改为并行收集器(-XX:+useSallelGC)。可以通过对java命令使用-XX:+UseSerialGC命令行选项来覆盖此默认值。

Initial Heap Size and Maximum Heap Size Changed for Parallel Garbage Collector
On server-class machines running either VM (client or server) with the parallel garbage collector (-XX:+UseParallelGC) the initial heap size and maximum heap size have changed as follows.
并行垃圾收集器的初始堆大小和最大堆大小已更改

在使用并行垃圾收集器(-XX:+usepallelgc)运行VM(客户端或服务器)的服务器类计算机上,初始堆大小和最大堆大小已更改如下。

initial heap size
Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before Java SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

初始堆大小

大于机器物理内存的1/64或合理的最小值。在JavaSE5.0之前,默认的初始堆大小是一个合理的最小值,随平台而异。可以使用-Xms命令行选项覆盖此默认值。

maximum heap size
Smaller of 1/4th of the physical memory or 1GB. Before Java SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.
最大堆大小

小于物理内存的1/4或1GB。在JavaSE5.0之前,默认的最大堆大小是64MB。可以使用-Xmx命令行选项覆盖此默认值。

Note: The boundaries and fractions given for the heap size are correct for Java SE 5.0. They are likely to be different in subsequent releases as computers get more powerful.
注意:堆大小的边界和分数对于JavaSE5.0是正确的。随着计算机功能的增强,它们在随后的版本中可能会有所不同。

Parallel Garbage Collector Throws Exception if Excessive Amount of Time Spent Collecting Small Amount of Heap
The parallel garbage collector (UseParallelGC) throws an out-of-memory exception if an excessive amount of time is being spent collecting a small amount of the heap. To avoid this exception, you can increase the size of the heap. You can also set the parameters -XX:GCTimeLimit=time-limit and -XX:GCHeapFreeLimit=space-limit where:
如果收集少量堆的时间过长,并行垃圾收集器将引发异常

如果收集少量堆的时间过长,并行垃圾收集器(usepallelgc)将抛出内存不足异常。要避免此异常,可以增大堆的大小。您还可以设置参数-XX:GCTimeLimit=time limit和-XX:gcHeapfReLimit=space limit,其中:

time-limit:
The upper limit on the amount of time spent in garbage collection in percent of total time (default is 98).

时间限制:

垃圾收集所用时间的上限(占总时间的百分比)(默认值为98)。

space-limit:
The lower limit on the amount of space freed during a garbage collection in percent of the maximum heap (default is 2).
空间限制:

垃圾收集期间释放的空间量的下限(以最大堆的百分比表示)(默认值为2)。

Implementation of -XX:+UseAdaptiveSizePolicy Used by Parallel Garbage Collector Changed
The implementation of -XX:+UseAdaptiveSizePolicy used by default with the -XX:+UseParallelGC garbage collector has changed to consider three goals:
a desired maximum GC pause goal
a desired application throughput goal
minimum footprint
The implementation checks (in this order):

-XX:+UseAdaptiveSizePolicy的实现与-XX:+useappallelgc垃圾收集器一起默认使用已更改为考虑三个目标:
期望的最大GC暂停目标
期望的应用程序吞吐量目标
最小空间
执行检查(按此顺序):


If the GC pause time is greater than the pause time goal then reduce the generations sizes to better attain the goal.
If the pause time goal is being met then consider the application's throughput goal. If the application's throughput goal is not being met, then increase the sizes of the generations to better attain the goal.
If both the pause time goal and the throughput goal are being met, then the size of the generations are decreased to reduce footprint.

如果GC暂停时间大于暂停时间目标,则减小生成大小以更好地实现该目标。

如果达到了暂停时间目标,则考虑应用程序的吞吐量目标。如果未达到应用程序的吞吐量目标,则增加生成的大小以更好地实现该目标。

如果同时满足了暂停时间目标和吞吐量目标,那么将减小生成的大小以减少占用空间。
Flags

-XX:MaxGCPauseMillis=nnn
A hint to the virtual machine that pause times of nnn milliseconds or less are desired. The VM will adjust the java heap size and other GC-related parameters in an attempt to keep GC-induced pauses shorter than nnn milliseconds. Note that this may cause the VM to reduce overall throughput, and in some cases the VM will not be able to meet the desired pause time goal.

需要向虚拟机发出暂停时间不超过nnn毫秒的提示。VM将调整java堆大小和其他与GC相关的参数,以尝试使GC引起的暂停小于nnn毫秒。请注意,这可能会导致VM降低总吞吐量,在某些情况下,VM将无法满足所需的暂停时间目标。

By default there is no pause time goal. There are definite limitations on how well a pause time goal can be met. The pause time for a GC depends on the amount of live data in the heap. The minor and major collections depend in different ways on the amount of live data. This parameter should be used with caution. A value that is too small will cause the system to spend an excessive amount of time doing garbage collection.

默认情况下没有暂停时间目标。对于停顿时间目标的实现有明确的限制。GC的暂停时间取决于堆中的活动数据量。次要和主要的收集以不同的方式取决于实时数据的数量。应谨慎使用此参数。值太小将导致系统花费过多时间进行垃圾收集。

-XX:GCTimeRatio=nnn
A hint to the virtual machine that it's desirable that not more than 1 / (1 + nnn) of the application execution time be spent in the collector.
For example -XX:GCTimeRatio=19 sets a goal of 5% of the total time for GC and throughput goal of 95%. That is, the application should get 19 times as much time as the collector.

例如-XX:GCTimeRatio=19将GC的目标设置为总时间的5%,将吞吐量目标设置为95%。也就是说,应用程序获得的时间应该是收集器的19倍。

By default the value is 99, meaning the application should get at least 99 times as much time as the collector. That is, the collector should run for not more than 1% of the total time. This was selected as a good choice for server applications. A value that is too high will cause the size of the heap to grow to its maximum.
默认情况下,该值为99,这意味着应用程序获得的时间至少是收集器的99倍。也就是说,收集器的运行时间不应超过总时间的1%。这是服务器应用程序的一个不错的选择。值太高将导致堆大小增长到最大值。

Suggested strategy
Do not choose a maximum value for the heap unless you know that the heap is greater than the default maximum heap size. Choose a throughput goal that is sufficient for your application.
除非知道堆大于默认的最大堆大小,否则不要为堆选择最大值。选择一个足以满足您的应用程序的吞吐量目标。

In an ideal situation the heap will grow to a value (less than the maximum) that will support the chosen throughput goal.
在理想情况下,堆将增长到支持所选吞吐量目标的值(小于最大值)。

If the heap grows to its maximum, the throughput cannot be met within that maximum. Set the maximum heap as large as you can, but no larger than the size of physical memory on the platform, and execute the application again. If the throughput goal can still not be met, then it is too high for the available memory on the platform.

如果堆增长到其最大值,则无法在该最大值内满足吞吐量。将最大堆设置为尽可能大,但不能大于平台上物理内存的大小,然后再次执行应用程序。如果吞吐量目标仍然无法实现,那么对于平台上的可用内存来说,它太高了。

If the throughput goal can be met but there are pauses that are too long, select a pause time goal. This will likely mean that your throughput goal will not be met, so choose values that are an acceptable compromise for the application.
如果吞吐量目标可以实现,但有太长的暂停,请选择暂停时间目标。这可能意味着您的吞吐量目标无法实现,因此请选择对应用程序来说是可接受的折衷方案的值。

你可能感兴趣的:(Java基础)