Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Key parameters of JVM and GC

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Key parameters of JVM memory

Parameters are set in tomcat/bin/catalina.sh

-server: server mode. If not configured, the default is-client, which must be used as the first parameter.

-Xms and-Xmx: the minimum and maximum values of the heap. The two values must be the same online. Set to the same to avoid reallocating the heap size after each GC. It is recommended that the maximum value of the heap be set to 80% of the maximum available memory (use the command free or cat / proc/meminfo to view, actual available physical memory = free+buffer+cache). However, if it is really set to 80%, the memory of the server may be too high and can be adjusted down a bit.

-Xmn: sets the size of the younger generation in the heap memory, and the rest is the size of the older generation. This value has a great impact on the performance of the system. Sun officially recommends that the configuration be configured as 3x8 of the entire heap.

-XX:NewRatio: indicates the ratio of the younger generation to the older generation. When the parameter-Xmn is removed, this parameter is used by default. The ratio is 2, that is, the younger generation accounts for 1max 3.

-XX:SurvivorRatio: if the ratio of two survivor regions to eden regions is set to 8, the ratio of two Survivor regions to one Eden region is 2:8, and one Survivor region accounts for 1x10 of the whole young generation.

-XX:PermSize and-XX:MaxPermSize (jdk1.7): the initial value of the permanent generation. The default is 1x64 of the physical memory, the maximum value of the permanent generation, and the default is 1x4 of the physical memory. It is recommended to set it to 128 and 512 respectively.

-XX:MetaspaceSize and-XX:MaxMetaspaceSize (jdk1.8): ditto

-Xss: sets the stack size of each thread. Each thread has a stack, which is used to hold function calls, return addresses, etc., which defaults to 1m and generally does not need to be modified.

-XX:+AlwaysPreTouch:jvm allocates memory when it starts, which is actually the effect of warm-up.

-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=path_address:jvm prints heap information when it crashes

If the equivalent of-Xms-Xmx-Xmn is not set in catalina.sh, you can view it on the following page. Refer to: https://blog.51cto.com/11009785/2396840

2. Parameters related to GC

-XX:+UseConcMarkSweepGC:CMS, concurrent collector (for the older generation)

-XX:CMSInitiatingOccupancyFraction=75 and-XX:+UseCMSInitiatingOccupancyOnly are used together to set CMS to start GC (control frequency, reduce frequency) when the memory occupancy reaches 75%. The second parameter means to use the previously set value. The default value is-1. You can view the set value by using the following command, where 2713 is changed to pid of java (viewed via ps-ef | grep java)

Jinfo-flag CMSInitiatingOccupancyFraction 2713

Keep in mind, however, that in most cases, JVM can make better garbage collection decisions than we can. Therefore, this flag should be used only if we have good reasons (such as testing) and have a deep understanding of the life cycle of the objects generated by the application.

-XX:+ExplicitGCInvokesConcurrent: execute GC in parallel in CMS without pausing to improve GC efficiency

-XX:+ParallelRefProcEnabled and-XX:+CMSParallelInitialMarkEnabled are used together to execute in parallel in CMS to reduce pause time

-XX:+CMSScavengeBeforeRemark: execute a ygc before the CMS GC (ygc for the younger generation and CMS GC for the older generation) to avoid CMS GC and ygc execution together to increase the pause time

-XX:+UseCMSCompactAtFullCollection:CMS will not defragment the heap. With this parameter, the surviving objects can be defragmented to reduce memory fragmentation.

-XX:CMSFullGCsBeforeCompaction=3: how many times to compress old generation after FullGC. The number of times it should be set for-XX:+UseCMSCompactAtFullCollection.

-XX:+CMSClassUnloadingEnabled: (useful only if UseConcMarkSweepGC is also enabled) whether class unloading is enabled when using the CMS garbage collection mechanism. This is disabled by default, and if you enable CMSClassUnloadingEnabled, garbage collection will clean up the persistent generation and remove classes that is no longer in use.

-XX:+PrintGCDateStamps-verbose:gc, print the details of GC in log

In general, according to the following style settings:

For more parameters and introduction, please refer to:

Https://www.cnblogs.com/hongdada/p/10277782.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report