JVM调优:GC 参数
生活随笔
收集整理的這篇文章主要介紹了
JVM调优:GC 参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:
- 《Memory Management in the Java HotSpot? Virtual Machine 》
- 《Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning 》
- 《Garbage Collector Ergonomics 》
一、??? 理論基礎
參見《[Java性能剖析]Sun JVM內存管理和垃圾回收 》
二、??? 配置說明(重要部分加粗)
1.??? Memory配置
1)??? Heap Space配置
- –Xmsn:初始堆空間,譬如-Xms512M
- –Xmxn:最大堆空間,譬如-Xmx1024M,一般可指定這兩個參數一致以避免在系統運行期間進行堆空間的調整
- –XX:MinHeapFreeRatio=minimum(默認40):當代空閑空間在代空間中比例大于maximum時,自動減少代空間以小于該值(將內存歸還給操作系統)
- –XX:MaxHeapFreeRatio=maximum? (默認70):當代空閑在代空間中比例小于minimum時,自動增長代空間以大于該值(向操作系統請求內存分配)
- -XX:YoungGenerationSizeIncrement=<Y>:Young Gen分配新內存時的增長比例,默認是20%(指符合MaxHeapFreeRatio時需要空間增長)
- -XX:TenuredGenerationSizeIncrement=<T>:Tenured Gen空間分配新內存時的增長比例,默認是20%(指符合MaxHeapFreeRatio時需要空間增長)
- -XX:AdaptiveSizeDecrementScaleFactor=<D>:空間縮小比例,如果空間增長比例是X,那么縮小比例是X/D(指符合MinHeapFreeRatio時需要空間縮小)
2)??? Perm Gen配置
- –XX:PermSize=n:默認持久區大小,譬如–XX:PermSize=32M(server模式下默認是16M)
- –XX:MaxPermSize=n:持久區最大空間,譬如–XX:MaxPermSize=128M,如果設置地過小,會導致OutOfMemory(PermSpace)錯誤(server模式下默認是64M)
3)??? 自適應目標設定(默認情況下JVM回自動調整Young Gen與Tenured Gen的比例、Eden Space與Suvivor的比例來達到性能目標)
- -XX:GCTimeLimit=time-limit :花費在GC上的時間上限,默認是98,當超過上限時,會拋出OutOfMemory(HeapSpace)的異常
- -XX:GCHeapFreeLimit=space-limit :Heap空閑空間的最低比例下限,默認是2,當超過下限時,會拋出OutOfMemory(HeapSpace)的異常
- -XX:MaxGCPauseMillis=nnn :最長的GC暫停時間,如果時間過長,會相應調整空間的大小(單位是毫秒)
- -XX:GCTimeRatio=nnn :最大的GC占總可用時間的比例,如果時間過長,會相應調整空間的大小(花費在GC上的時間比例不超過1 / (1 + nnn))
GC的處理優先級是MaxGCPauseMillis最高,GCTimeRatio次之,其他的空間大小配置優先級最低
4)??? Young Gen/Eden Space/Suvivor Space配置
- -XX:-UseAdaptiveSizePolicy :不使用自適應自動調整空間大小,要使用后面的配置,必須先配置這個選項(可以使用-XX:+UseAdaptiveSizePolicy啟動自適應自動調整空間大小)
- –XX:NewSize=n:默認Young Gen的大小,譬如–XX:NewSize=400M
- -XX:MaxNewSize=n:Young Gen的最大大小,譬如–XX:MaxNewSize=400M
- –XX:NewRatio=n(默認server模式是8,client模式是2):Young Gen與Tenured Gen的比例
- –XX:SurvivorRatio=n(默認是32):Eden Space與Survivor Space的比例,譬如–XX:SurvivorRatio=7,則每個Survivor Space占整個Young Gen的1/9(注意,有兩個Survivor區)
5)??? Thread Stack Space
- -XX:ThreadStackSize=<value>或-Xssn<value>:設置線程的棧大小(字節數)(0表示默認) [Sparc: 512, Solaris Intel: 256, Sparc 64bit: 1024 all others 0] GC配置,一般使用默認值即可
2.GC配置
1)??? Parallel and Parallel Compacting Collectors配置
- -XX:+UseParallelGC :啟用Parallel Collector
- -XX:+UseParallelOldGC :啟用Parallel Compacting Collector
- -XX:ParallelGCThreads=<N> :并行垃圾回收線程數(默認不需調整,與服務器的內核數一致)
2)??? CMS配置(這部分為了避免我的理解錯誤,直接給出E文說明)
- -XX:+UseConcMarkSweepGC:啟用CMS垃圾回收器
- -XX:+CMSIncrementalMode :Enables incremental mode. Note that the concurrent collector must also be enabled (with -XX:+UseConcMarkSweepGC) for this option to work.(disabled)
- -XX:+CMSIncrementalPacing :Enables automatic pacing. The incremental mode duty cycle is automatically adjusted based on statistics collected while the JVM is running. (enabled) (Enables automatic control of the amount of work the CMS collector is allowed to do before giving up the processor, based on application behavior.)
- -XX:CMSIncrementalDutyCycle=<N> The percentage (0-100) of time between minor collections that the concurrent collector is allowed to run. If CMSIncrementalPacing is enabled, then this is just the initial value. (default 10)
- -XX:CMSIncrementalDutyCycleMin=<N> The percentage (0-100) which is the lower bound on the duty cycle when CMSIncrementalPacing is enabled. 10 0 -XX:CMSIncrementalSafetyFactor=<N> The percentage (0-100) used to add conservatism when computing the duty cycle. 10 10 -XX:CMSIncrementalOffset=<N> The percentage (0-100) by which the incremental mode duty cycle is shifted to the right within the period between minor collections. (default 0)
- -XX:CMSExpAvgFactor=<N> The percentage (0-100) used to weight the current sample when computing exponential averages for the concurrent collection statistics. (default 25)
?
總結
以上是生活随笔為你收集整理的JVM调优:GC 参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jackson json 转换Bean,
- 下一篇: JVM调优: 转载JVM调优总结