jvm gc相关

简介:

1. 杂类

http://www.oracle.com/technetwork/java/faq-140837.html 

*    -XX:+UseParallelGC : 和传统的新生代GC一样,只是可以进行并行标记处理。 可通过-XX:ParallelGCThreads指定并发线程数,默认值:-XX:ParallelGCThreads =<#cpus < 8 ? #cpus : 3 + ((5 * #cpus) / 8) >


1.The new parallel garbage collector is similar to the young generation collector in the default garbage collector but uses multiple threads to do the collection. By default on a host with N CPUs, the parallel garbage collector uses N garbage collector threads in the collection. The number of garbage collector threads can be controlled with a command line option (see below). On a host with a single CPU the default garbage collector is used even if the parallel garbage collector has been requested. On a host with 2 cpus the Parallel garbage collector generally performs as well as the default garbage collector and a reduction in the young generation garbage collector pause times can be expected on hosts with more than 2 cpus.  


* XX:+UseParNewGC: 和UseParallelGC类似,也是并行处理,但实现技术还是不同,据说在新生代的火车模型上有更少的停顿时间。

 

-XX:+ DisableExplicitGC : 禁用system.gc()调用


1.Don't call System.gc(). The system will make the determination of when it's appropriate to do garbage collection and generally has the information necessary to do a much better job of initiating a garbage collection. If you are having problems with the garbage collection (pause times or frequency), consider adjusting the size of the generations. 

* -XX:+AggressiveOpts 加快编译 

 

* -XX:+UseBiasedLocking 锁机制的性能改善。

 

* -Xss=256k


1.-Xss 是线程栈的大小, 这个参数需要严格的测试, 一般小的应用, 如果栈不是很深, 应该是128k够用的, 不过,我们的应用调用深度比较大, 还需要做详细的测试。 这个选项对性能的影响比较大。 建议使用256K的大小.  

2. CMS介绍

文章:http://www.iteye.com/topic/473874

 

 

-XX:+CMSParallelRemarkEnabled : 在和UseParNewGC一起使用的情况下,尽量减少mark的时间

 

-XX:+UseConcMarkSweepGC : 指定在Old Generation使用concurrent gc

 

-XX:+UseCMSCompactAtFullCollection : 在使用concurrent gc的情况下,防止memory fragmention

 

-XX:CMSInitiatingOccupancyFraction=n : 指示在old generation在使用了n%的后,触发cms gc

 

-XX:+UseCMSInitiatingOccupancyOnly : 指示只有在old generation在使用了初始化的比例后启动cms gc

 

 

公司参数列表记录:


1.-server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m  
2.-Xss256k  
3.-XX:+DisableExplicitGC  
4.-XX:+UseConcMarkSweepGC  
5.-XX:+CMSParallelRemarkEnabled  
6.-XX:+UseCMSCompactAtFullCollection  
7.-XX:LargePageSizeInBytes=128m  
8.-XX:+UseFastAccessorMethods  
9.-XX:+UseCMSInitiatingOccupancyOnly  
10.-XX:CMSInitiatingOccupancyFraction=70 

3. G1介绍

 

http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html

 

jdk 1.6.14中首次引入了G1. 

 

G1的特点描述: 

 

  1. 并发性和并行性。 充分利用系统硬件资源,多核多CPU的资源,通过多线程并发和并行技术,尽量减少“stop-the-world”,也就是系统停顿时间。
  2. 代收集。 和普通的GC收集器一样,区分young对象和old对象为不同的收集策略。针对young区关注的是存活的对象,因为young大多数都是需要被GC回收的。
  3. 压缩。 不同于CMS收集,G1垃圾收集器一直都会对heap区做压缩,避免内存碎片的产生。
  4. 可预测性。G1相比于CMS针对GC的“stop-the-world”的有更好的可预测性,主要归功于G1的压缩避免内存碎片对GC pause time的影响,G1还有相应的预测模型,通过许多方式,尽量去满足一个pause time的预期。
G1和CMS不同点:
  1. G1没有严格的young,old区的划分,它将整个heap区当作是一个连续的物理内存块进行处理。这样G1可以很方便,很灵活的进行对象的拷贝和移动。
  2. G1同样有from/to的survivors regoins
  3. G1和CMS一样会有 concurrent marking phase,通过并发从root对象进行存活对象进行标记,但是它与CMS相比,没有concurrent sweeping phase处理

G1相关参数:
  1. -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC (开启使用G1 GC)
  2. -XX:MaxGCPauseMillis =50 (for a pause time target of 50ms)
  3. -XX:GCPauseIntervalMillis =200 (for a pause interval target of 200ms)
  4. -XX:+G1YoungGenSize=512m  (for a 512 megabyte young generation) 这里搞不明白,是G1重新划分新生代?还是仅仅只是在GC中划分的区域。
  5.  -XX:SurvivorRatio=6 调整surivor regoins的大小
  6. -XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled 不知道干吗的,先记着

4. gc相关调试参数:


打印GC时间参数: -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/home/test/logs/gc.log 

.

1.49.414: [GC [PSYoungGen: 10480K->0K(524160K)] 11272K->792K(2097024K), 0.0002270 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]   

显示在程序运行的49.414发生了Minor的垃圾收集,前一段数据针对新生区,从10480K整理为0k,新生区总大小为524160K,程序暂停了0.2ms,而后一段数据针对整个堆。

详细暂停时间参数: -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime
 

5. GC算法组合

GC的算法
复制(Copying)
标记-清除(Mark-Sweep)
标记-清除-整理(Mark-Sweep-Compact)
 

 

三种垃圾收集器
Serial GC
Parallel GC/Parallel Old GC
Concurrent Mark-Sweep GC (CMS)

 

GC算法组合:

 

说明:

  • UseSerialGC:"Serial" + "Serial Old"
  • UseParNewGC:"ParNew" + "Serial Old"
  • UseConcMarkSweepGC:"ParNew" + "CMS" + "Serial Old". "CMS" is used most of the time to collect the tenured generation. "Serial Old" is used when a concurrent mode failure occurs.
  • UseParallelGC:"Parallel Scavenge" + "Serial Old"
  • UseParallelOldGC:"Parallel Scavenge" + "Parallel Old"

如果GC算法参数搭配不合理,会出现类似错误:

写道
Conflicting collector combinations in option list; please refer to the release notes for the combinations allowed
Could not create the Java virtual machine. 


相关文章
|
3月前
|
算法 Java
太狠了!阿里技术专家撰写的电子版JVM&G1 GC实战,颠覆了传统认知
JVM是Java语言可以跨平台、保持高发展的根本,没有了 JVM, Java语言将失去运行环境。针对 Java 程序的性能优化一定不可能避免针对JVM 的调优,随着 JVM 的不断发展,我们的应对措施也在不断地跟随、变化,内存的使用逐渐变得越来越复杂。所有高级语言都需要垃圾回收机制的保护,所以 GC 就是这么重要。
|
3月前
|
算法 Java
JVM GC和常见垃圾回收算法
JVM GC和常见垃圾回收算法
48 0
|
3月前
|
缓存 监控 算法
jvm性能调优实战 - 39一次大促导致的内存泄漏和Full GC优化
jvm性能调优实战 - 39一次大促导致的内存泄漏和Full GC优化
68 0
|
4月前
|
存储 缓存 算法
JVM(四):GC垃圾回收算法
JVM(四):GC垃圾回收算法
|
3月前
|
架构师 Java
jvm性能调优实战 - 35电商APP后台系统如何对Full GC进行深度优化
jvm性能调优实战 - 35电商APP后台系统如何对Full GC进行深度优化
52 0
|
3月前
|
存储 监控 算法
垃圾回收器、垃圾回收算法、空间分配担保、JVM调优、GC回收对象的过程
垃圾回收器、垃圾回收算法、空间分配担保、JVM调优、GC回收对象的过程
|
3月前
|
存储 分布式计算 前端开发
jvm性能调优实战 - 26一个每秒10万并发的系统如何频繁发生Young GC的
jvm性能调优实战 - 26一个每秒10万并发的系统如何频繁发生Young GC的
61 0
|
2月前
|
算法 Java
深入理解JVM - 解读GC日志
深入理解JVM - 解读GC日志
50 0
|
3月前
|
算法 Java
JVM GC 垃圾回收
【1月更文挑战第3天】JVM GC 垃圾回收
|
3月前
|
存储 算法 Java
JVM GC 算法
对于JVM的垃圾收集(GC),这是一个作为Java开发者必须了解的内容,那么,我们需要去了解哪些内容呢,其实,GC主要是解决下面的三个问题: 哪些内存需要回收? 什么时候回收? 如何回收? 回答了这三个问题,也就对于GC算法的原理有了最基本的了解。