JRockit垃圾回收優化參數

網上的調優文章不少,我的認爲調整參數優化項目這個事情和內部代碼有很大關係,常駐大內存和小內存更多線程的配置必定是不同的,我記錄的只是公司項目的調優:) 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區域的大小,默認以下

Table 2-7 Default Nursery Sizes
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

相關文章
相關標籤/搜索