网上的调优文章很多,个人认为调整参数优化项目这个事情和内部代码有很大关系,常驻大内存和小内存更多线程的配置一定是不一样的,我记录的只是公司项目的调优:)
1.选择一个适合自己的垃圾回收类型:
对于JRockit可能和hotspot有很大不同的就是垃圾回收器的算法,选择一个合适项目的很不容易,查看http://daigong.sinaapp.com/?p=115
我选择的是并发回收,因为项目比较要求实时性,对吞吐量的要求还算好,但不能容忍服务长时间在线程暂停
-Xgcprio:pausetime #使用控制暂停时间的策略
-XpauseTarget #设置期待的控制时间,这个时间会被垃圾回收参考,但是不是绝对的服从该时间
-Xgc:gencon #启用并发回收器
-XXnoSystemGC #这个防止代码级别调用system.gc()
-Xns
-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).
设置Nursery区域的大小,默认如下
Options used
|
Default value
|
---|---|
-server (default)
|
50% of free heap
|
-client
|
None; the default garbage collector in -client mode is single-spaced.
|
-Xgc:gencon
|
10 MB per logical processor
|
-Xgc:genpar
|
50% of free heap
|
-Xgcprio:throughput
|
10 MB per logical processor
|
-Xgcprio:pausetime
|
50% of free heap
|
我使用的是-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