网上的调优文章不少,我的认为调整参数优化项目这个事情和内部代码有很大关系,常驻大内存和小内存更多线程的配置必定是不同的,我记录的只是公司项目的调优:) html
1.选择一个适合本身的垃圾回收类型: java
对于JRockit可能和hotspot有很大不一样的就是垃圾回收器的算法,选择一个合适项目的很不容易,查看http://daigong.sinaapp.com/?p=115 算法
我选择的是并发回收,由于项目比较要求实时性,对吞吐量的要求还算好,但不能容忍服务长时间在线程暂停 多线程
-Xgcprio:pausetime #使用控制暂停时间的策略 并发
-XpauseTarget #设置期待的控制时间,这个时间会被垃圾回收参考,可是不是绝对的服从该时间 oracle
-Xgc:gencon #启用并发回收器 app
-XXnoSystemGC #这个防止代码级别调用system.gc() less
-Xns jvm
-Xns sets the nursery size. the JRockit JVM uses a nursery when the generational garbage collection model is used, that is, when the dynamic garbage collector has determined that the generational garbage collection model should be used or when the static generational concurrent garbage collector ( -Xgc : gencon) has been selected. You can also use -Xns to set a static nursery size when running a dynamic garbage collector (-XgcPrio). jsp
设置Nursery区域的大小,默认以下
我使用的是-Xgc:gencon,默认才有10m*8 – -# 这也致使了GC cpu居高不下,由于一直忙乎在Nursery 到 Old的内存迁移,须要注意的是这个Nursery区域过大的话,会致使每次Nursery垃圾回收的效率下降,使用时间较长,由于大内存须要更多的扫描时间麻~
-XXkeepAreaRatio
This option sets the size of the keep area within the nursery as a percentage of the nursery. The keep area prevents newly allocated objects from being promoted to old space too early.
设置Nursery区域的回收时机,在空闲比率多少的时候进行回收
ps.我开始调优的时候将这个属性设置为0,发现这种设置下,JRockit会本身调整回收策略,从并发变成并行回收,这样的回收策略会致使java其余线程暂停,这不是咱们想要的结果,最后我将这个值5%,跟了很久log,没有发现策略转换的问题。
-XXgcTrigger
This option determines how much free memory should remain on the heap when a concurrent garbage collection starts. If the heap becomes full during the concurrent garbage collection, the Java application can’t allocate more memory until the garbage collection frees some heap space, which might cause the application to pause. While the trigger value will tune itself in runtime to prevent the heap from becoming too full, this automatic tuning may take too long. Instead, you can use -XXgcTrigger to set from the start a garbage collection trigger value more appropriate to your application.
If the heap becomes full during the concurrent mark phase, the sweep phase will revert to parallel sweep (unless -XXnoParSweep has been specified). If this happens frequently and the garbage collection trigger doesn’t increase automatically to prevent this, use -XXgcTrigger to manually increase the garbage collection trigger.
这个参数比较奇怪,我理解为整个heap的free小于这个比虑的话才会回收,可是事实是Old 和 Nursery区域依然会正常工做,若是压力忽然增大,2个垃圾回收器没有充分回收垃圾,这个参数的设置才会体现出来。
这俩个参数是可让程序打印出垃圾回收的详情,看下一下就知道,咱们关注的主要是时间信息,运行期就不要搞出来了。
-Xverbose:memory
-Xverbose:memdbg
最后的完整参数
JAVA_OPTS='-server -Xms2048m -Xmx2048m -Xgcprio:pausetime -XpauseTarget50ms -Xgc:gencon -XXkeepAreaRatio=5 -XXgcTrigger:10 -XXnoSystemGC -Xverbose:memory'
X属性配置参考:
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html
XX属性配置参考
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionXX.html
还有一些老外讨论sunjdk 和 JRockit的区别的帖子
https://forums.oracle.com/forums/thread.jspa?threadID=700803