当前位置:网站首页>JVM parameter setting and analysis
JVM parameter setting and analysis
2022-06-27 13:27:00 【User 3147702】
1. summary
In the previous article, I introduced jvm Memory management and garbage collection , Combine these theoretical knowledge , The performance of the system can be improved by reasonably setting parameters .
2. JVM main parameter
2.1. Basic setting parameters
JVM The main meaning of setting parameters
Parameter name | meaning | The default value is | explain |
|---|---|---|---|
-Xms | Minimum heap size | Physical memory 1/64(<1GB) | Free heap memory is less than 40%( adopt MinHeapFreeRatio Parameter to adjust the threshold ) when ,jvm Will increase the heap until -Xmx |
-Xmx | Maximum heap size | Physical memory 1/4(<1GB) | Free heap memory is greater than 70%( adopt MaxHeapFreeRatio Parameter to adjust the threshold ) when ,jvm Will reduce the heap until -Xms |
-Xmn | The size of the new generation | nothing | finger Eden With two Survivor Sum of space ,Sun The official recommendation is to configure the entire heap as 3/8 |
-XX:PermSize | Method area ( Forever ) size | Physical memory 1/64 | - |
-Xss | Stack size per thread | 1M | - |
-XX:ThreadStackSize | Thread stack size | 1M | The main thread uses -Xss Set as primary , Other threads are dominated by this setting , Generally, the default value can be used |
-XX:NewRadio | The ratio of the size of the new generation to that of the old generation | nothing | Xms=Xmx And set up Xmn Under the circumstances , This parameter does not need to be set |
-XX:SurvivorRatio | Eden Area Survivor The ratio of area size | nothing | - |
-XX:LargePageSizeInBytes | Memory page size | 128M | Cannot be set too large |
-XX:+UseFastAccessorMethods | Whether to use the quick optimization of the original type | nothing | - |
-XX:+DisableExplicitGC | Whether to shut down System.gc() | nothing | - |
-XX:MaxTenuringThreshold | The maximum age of garbage | nothing | N The new generation resources that have not been recycled will be automatically put into the old generation , Only use serial GC Only when effective |
-XX:MaxGCPauseMillis | Maximum pause time | - | The maximum time for each young generation garbage collection |
-Xnoclassgc | Jinyong garbage recycling | nothing | - |
-XX:SoftRefLRUPolicyMSPerMB | no M Soft reference lifetime in heap memory | 1s | - |
-XX:PretenureSizeThreshold | Objects over how large are automatically allocated in older generations | 0 | use Parallel Scavenge GC When is invalid |
-XX:TLABWasteTargetPercent | TLAB Occupy eden % of area | 1% | - |
-XX:+CollectGen0First | FullGC Whether it's first or not YGC | false | - |
2.2. Collect related parameters in parallel
JVM parallel GC Setting parameters of
Parameter name | meaning | The default value is | explain |
|---|---|---|---|
-XX:+UseParGC | Use ParNew The collector is used for new generation collection | false | And -XX:+UseConcMarkSweepGC identical |
-XX:ParallelGCThreads | Number of parallel collection threads | - | Specify parallelism GC Number of garbage collection threads under , It is better to configure it as the same as CPU The numbers are equal |
-XX:+UseParallelOldGC | Set the older generation collector to Parallel Old | JDK1.6 Start to offer | - |
-XX:+UseAdaptiveSizePolicy | Automatically select younger generation size and Survivor The proportion | false | It is recommended to keep the parallel collector open |
-XX:GCTimeRatio | Set the garbage collection time as a percentage of the program running time | nothing | Greater than 0 Less than 100, Use Parallel Scavenge Set when |
-XX:+UseAdaptiveSizePolicy | Whether to automatically determine the maximum throughput limit according to the current system conditions | false | Use Parallel Scavenge Set when |
-XX:+ScavengeBeforeFullGC | Full GC Pre invocation YGC | true | - |
2.3. CMS Related parameters
JVM CMS GC Setting parameters of
Parameter name | meaning | The default value is | explain |
|---|---|---|---|
-XX:+UseConcMarkSweepGC | Enable CMS GC | false | - |
-XX:CMSFullGCsBeforeCompaction | How many times GC After that, perform a memory compression ( Defragmentation ) | - | - |
-XX:+CMSParallelRemarkEnabled | Lower the mark pause | false | - |
-XX+UseCMSCompactAtFullCollection | Whether to enable memory compression ( Defragmentation ) | - | Recommended Opening |
-XX:+UseCMSInitiatingOccupancyOnly | Manual trigger CMS | false | prohibit HotSpot Automatic triggering CMS GC |
-XX:CMSInitiatingOccupancyFraction | GC Trigger threshold ( percentage ) | 1.5 by 68,1.6 by 92 | When the memory usage reaches the threshold, it starts GC, Setting up a meeting may lead to failure full GC |
-XX:+CMSIncrementalMode | Set to incremental mode | false | Apply to single CPU Next , stay CMS Pause during operation , Continue running the user thread , Next increment GC |
-XX:CMSClassUnloadingEnabled | When the garbage collection cleans up the method area, remove those that are no longer used classes | - | - |
-XX:+CMSPermGenSweepingEnabled | Whether to clean the method area ( Forever ) | - | The default is not to clean |
3. Set rules
3.1. Young generation size choice
1. Response time first applications — Increase the size of the younger generation as much as possible , This also means that the size of the old age will be relatively reduced , So at the same time, we should reduce the number of objects reaching the old age 2. Throughput priority application — As many young people as possible , Parallel garbage collection can be selected , fit 8CPU The above applications
in any case , Remember not to set the new generation too small , Otherwise, it will cause a new generation GC frequent , Even let the new generation objects directly enter the old generation , triggering full GC.
3.2. Old age size choice
1. Response time first applications — Usually used in the old days CMS Concurrent collection , So we can't design too small in the old age , Otherwise, too much memory will cause frequent full GC; If the design is too large , You need a longer collection , Therefore, it is necessary to collect information in combination with concurrency 、 Number of persistent concurrent collections 、 Tradition GC Information 、 The time ratio of the younger generation and the older generation takes into account the specific memory size 2. Throughput priority application — Such an application usually requires a younger generation + Young and old generation , In this way, most short-term objects can be recycled as much as possible , Reduce the number of medium-term objects , In the old age, long-lived objects are stored
3.3. Memory fragmentation in the old days
If you use CMS As a collector for the elderly , So because of the mark removal algorithm he adopted , It usually causes debris , If the final space is insufficient , It will trigger once full GC. In this case , The following configuration is required : 1. -XX:+UseCMSCompactAtFullCollection — When using concurrent collectors , Turn on the compression of the old 2. -XX:CMSFullGCsBeforeCompaction=0 — When the above configuration is on , How many times is it set here Full GC after , Compress the old generation
3.4. Other matters
1. linux 64 Bit operating system ,jdk Consume more memory , Slower execution , But throughput is bigger 2. XMX and XMS The setting is the same size ,MaxPermSize and MinPermSize The setting is the same size , This can reduce the pressure of the size of the telescoping heap 3. Use CMS The advantage is to use as few new generations as possible , The empirical value is 128M-256M, And then the old generation uses it CMS Parallel collection , This can ensure the low latency throughput of the system . actually cms The collection pause time of is very short ,2G Of memory , about 20-80ms Application pause time 4. When the system stops, it may be GC The problem may also be the problem of the program , multi-purpose jmap and jstack see , perhaps killall -3 java, Then check it out java Console log , Can see a lot of problems . 5. If cache is used , So the old generation should be older 6. When using concurrent recycle , Younger generation is a little smaller , Old age is big , Because old age is a big use of concurrent recycling , Even if the time is long, it will not affect other programs to continue to run , The site doesn't stop
4. Problem analysis — promotion failed
produce promotion failed It may be caused by two reasons : 1. A new generation of survivor Insufficient , Many objects in the young generation are waiting to be put into survior Memory , the Survivor The space is insufficient , These memories are put into the old generation 2. There is not enough memory in the old age to accept objects from the younger generation
Solve this problem , We should start from these two reasons : 1. increase Survivor Area size , Set up -XX:SurvivorRatio=1 2. Reduce CMSInitiatingOccupancyFraction( If set to 70), Let the older generation be recycled at a lower threshold
It can be inferred that :eden+from survivor < old gen When memory is left , There will be no promontion faild The situation of , namely : (Xmx-Xmn)(1-CMSInitiatingOccupancyFraction/100)>=(Xmn-Xmn/(SurvivorRatior+2)) obtain :CMSInitiatingOccupancyFraction <=((Xmx-Xmn)-(Xmn-Xmn/(SurvivorRatior+2)))/(Xmx-Xmn)100.
边栏推荐
猜你喜欢
随机推荐
【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(一)
爱可可AI前沿推介(6.27)
Bluetooth health management device based on stm32
数字化新星何为低代码?何为无代码
【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(三)
Implementation of recruitment website based on SSM
IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module
Pyqt, pyside slot functions are executed twice
Shake hands with life and make peace
内网学习笔记(8)
L June training (day 27) - figure
【周赛复盘】LeetCode第81场双周赛
【医学分割】unet3+
Good luck today
Different habits
awk 简明教程
云原生(三十) | Kubernetes篇之应用商店-Helm
VS调试技巧
Daily question brushing record (6)
C语言 函数指针与回调函数
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)








