HotSpot GC及参数设置

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

1)Pause时间

2)Throughput

 

GC类型有:

1. 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:+UseSerialG

 

2. 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.

  • Newparallel 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

 

 

3. 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.

 

4. The Incremental Low Pause Collector

       -XX:+UseTrainGC

 

 

下面介绍一下各种参数的意义

1.  -Xms  -Xmx

     Heap 内存设置

     堆内存不是一下子就分配-Xmx大小的,随着GC的进行,从-Xms慢慢递增的

     基本来说Heap内存分配太大的话,GC的次数会减少,但是做一次GC的Pause时间会很大。反之亦然。

 

2.  -Xincgc

      Incremental GC,也即GC的Train算法,  增量GC一次只收集部分Heap对象,而不是针对整个堆。如果GC Pause 时间太长的话可以考虑用这个选项调试一下

 

3. -Xss

      栈大小设置,从Java6开始,32-bit JVM默认是320k,64-bit JVM默认是1024k。(题外话,64-bit JVM并不会所有类型double一下,只是可分配的Heap内存和线程数会更多)

      注意栈大小设置太小的话,递归多的话会出现栈溢出;栈太大的话,如果Application中线程比较多(每个线程有自己的栈),可分配的栈变少,就会出现 running out of memeory问题。

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值