HotSpot GC及参数设置

2017/02/12 iteye

JVM参数调整无非是调整堆中各种内存的大小,选择最优的GC算法(行为)。一般有两个指标来考量:

  • Pause时间
  • Throughput  

GC类型有:

Serial GC

The serial collector uses a single thread to perform all garbage collection work, which makes it relatively efficient since there is no communication overhead between threads. It is best-suited to single processor machines, since it cannot take advantage of multiprocessor hardware, although it can be useful on multiprocessors for applications with small data sets (up to approximately 100MB). The serial collector is selected by default on certain hardware and operating system configurations, or can be explicitly enabled with the option -XX:+UseSerialGC

The Throughput Collector  

-XX:+UseParallelGC主要是针对young generation的,Tenured Generation还是Serial Collector   The parallel collector (also known as the throughput collector) performs minor collections in parallel, which can significantly reduce garbage collection overhead. It is intended for applications with medium- to large-sized data sets that are run on multiprocessor or multi-threaded hardware. The parallel collector is selected by default on certain hardware and operating system configurations, or can be explicitly enabled with the option -XX:+UseParallelGC.

New: parallel compaction is a feature introduced in J2SE 5.0 update 6 and enhanced in Java SE 6 that allows the parallel collector to perform major collections in parallel. Without parallel compaction, major collections are performed using a single thread, which can significantly limit scalability. Parallel compaction is enabled by adding the option -XX:+UseParallelOldGC to the command line    

The Concurrent Low Pause Collector      

-Xincgc or  -XX:+UseConcMarkSweepGC 主要是正对Tenure Generation的   The concurrent collector performs most of its work concurrently (i.e., while the application is still running) to keep garbage collection pauses short. It is designed for applications with medium- to large-sized data sets for which response time is more important than overall throughput, since the techniques used to minimize pauses can reduce application performance. The concurrent collector is enabled with the option -XX:+UseConcMarkSweepGC.  

The Incremental Low Pause Collector       

-XX:+UseTrainGC     下面介绍一下各种参数的意义

  • -Xms  -Xmx      Heap 内存设置      堆内存不是一下子就分配-Xmx大小的,随着GC的进行,从-Xms慢慢递增的      基本来说Heap内存分配太大的话,GC的次数会减少,但是做一次GC的Pause时间会很大。反之亦然。   + -Xincgc       Incremental GC,也即GC的Train算法,  增量GC一次只收集部分Heap对象,而不是针对整个堆。如果GC Pause 时间太长的话可以考虑用这个选项调试一下  
  • -Xss       栈大小设置,从Java6开始,32-bit JVM默认是320k,64-bit JVM默认是1024k。(题外话,64-bit JVM并不会所有类型double一下,只是可分配的Heap内存和线程数会更多)       注意栈大小设置太小的话,递归多的话会出现栈溢出;栈太大的话,如果Application中线程比较多(每个线程有自己的栈),可分配的栈变少,就会出现 running out of memeory问题。

Server 和 Client端GC策略不同,考虑到可用的Heap Size,CPU数量等。

Search

    Table of Contents