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

What are the parameters commonly used in JVM performance tuning

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "what are the commonly used parameters in JVM performance tuning". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Brief introduction of JVM tuning parameters JVM parameters

The-XX parameter is called an unstable parameter, so called because the setting of such parameters can easily lead to differences in JVM performance, making JVM extremely unstable. If such parameters are set reasonably, the performance and stability of JVM will be greatly improved.

Parameter syntax rules Boolean type parameter values

-XX:+ [param],'+ 'means to enable this option

-XX:- [param],'- 'means to disable this option

Numeric type parameter value

-XX: [param] = sets a numeric type value for the option, which can be followed by units, such as'm'or'M 'for megabytes,' k'or'K 'kilobytes, and' g' or'G' gigabytes. 32K is the same size as 32768.

String type parameter values:

-XX: [param] = sets a string type value for the option, which is usually used to specify a file, path, or list of commands.

For example:-XX:HeapDumpPath=./dump.coreJVM parameter example

Configuration:-Xmx4g-Xms4g-Xmn1200m-Xss512k-XX:NewRatio=4-XX:SurvivorRatio=8-XX:PermSize=100m-XX:MaxPermSize=256m-XX:MaxTenuringThreshold=15

Parsing:

-Xmx4g: the maximum heap memory is 4GB. (shorthand sets the whole heap memory size = 4G) you don't have to set the size as a numeric value:-XX: [param] = 4G, maximum heap size, default physical memory 1max 4

-Xms4g: initializes the heap memory to 4GB. Initial heap size, the default physical memory of 1 Acme 64.

-Xmn1200m: set the size of younger generation to 1200MB. With the increase of the younger generation, the size of the older generation will be reduced. This value has a great impact on system performance, and Sun officially recommends that it be configured as 3Universe 8 of the entire heap.

-Xss512k: sets the stack size for each thread. After JDK5.0, the stack size of each thread is 1MB, and the previous stack size of each thread is 256K. Should be adjusted according to the amount of memory required by the application thread. Decreasing this value generates more threads under the same physical memory. However, the operating system still has a limit on the number of threads in a process, which cannot be generated indefinitely, and the experience value is about 3000 to 5000. If too young, it may also cause stackOverflow.

-XX:NewRatio=4: sets the ratio of the younger generation (including Eden and two Survivor zones) to the older generation (excluding the persistent generation). If set to 4, the ratio of the younger generation to the older generation is 1:4, and the younger generation accounts for 1 prime 5 of the whole stack.

-XX:SurvivorRatio=8: sets the ratio of the size of the Eden region to the Survivor region in the younger generation. If set to 8, the ratio of two Survivor regions to one Eden region is 2:8, and one Survivor region accounts for 10% of the whole younger generation.

-XX:PermSize=100m: initialize the permanent generation size to 100MB. * * initial value of permanent generation. Default is 1x64 of physical memory * *

-XX:MaxPermSize=256m: set the persistent generation size to 256MB. * * maximum value of permanent generation, default is 1x4 of physical memory * *

-XX:MaxTenuringThreshold=15: set the maximum age of garbage. If set to 0, the younger generation will enter the older generation without going through the Survivor area.

For more applications of the older generation, it can improve the efficiency. If you set this value to a large value, the younger generation object will be replicated multiple times in the Survivor area, which can increase the survival time of the younger generation of the object and increase the overview of being recycled in the younger generation.

(however, large objects must carefully consider whether to set an appropriate threshold, otherwise there will be large object replication, causing problems.)

JVM tuning case

First of all, let's introduce the new generation and the old age. The so-called new generation and the old age are defined according to the generation collection algorithm, and the new generation is divided into two areas: Eden and Survivor. Plus the only three districts in the old days. The data is first allocated to the Eden area (of course, there are special cases where large objects are put directly into the old age (large objects are java objects that require a lot of contiguous memory space). When Eden does not have enough space, it will trigger jvm to initiate a Minor GC. If the object survives after a Minor GC and is accepted by the Survivor space, it will be moved to the Survivor space. And set its age to 1, each time the object gets through the Minor GC in Survivor, the age will be increased by 1. When the age reaches a certain level (the default is 15), it will be promoted to the old age, of course, the age of promotion can be set.

Heap size setting

The maximum heap size in JVM is limited in three ways:

Data model (32-bt or 64-bit) restrictions for related operating systems

System's available virtual memory limit

System's available physical memory addressing limit: 32-bit system is generally limited 1.5Gbps 2Gbot 64bit system has no memory limit

Typical settings:

-Xmx3550m-Xms3550m-Xmn2g-Xss128k

Let's repeat it again (make a deep impression):

-Xmx3550m: set the maximum available memory of JVM to 3550m.

-Xms3550m: set the minimum memory of JVM to 3550m. This value can be set to the same as-Xmx to prevent JVM from reallocating memory after each garbage collection.

-Xmn2g: set the size of the younger generation to 2G. Whole JVM memory size = younger generation size + older generation size + persistent generation size. The permanent generation usually has a fixed size of 64m, so increasing the size of the younger generation will reduce the size of the old generation. This value has a great impact on system performance, and Sun officially recommends that it be configured as 3Universe 8 of the entire heap.

-Xss128k: sets the stack size for each thread. The stack size of each thread after JDK5.0 is 1m, and the stack size of each thread before is 256K.

-Xmx3550m-Xms3550m-Xss128k-XX:NewRatio=4 (the proportion of newborn and elderly areas is 1:5)-XX:SurvivorRatio=4 (Eden and survivors (single) 1:6)-XX:MaxPermSize=16m-XX:MaxTenuringThreshold=0

The following is explained:

-XX:NewRatio=4: sets the ratio of the younger generation (including Eden and two Survivor zones) to the older generation (excluding the persistent generation). If set to 4, the ratio of the younger generation to the older generation is 1:4, and the younger generation accounts for 1 prime 5 of the whole stack.

-XX:SurvivorRatio=4: sets the ratio of the size of the Eden region to the Survivor region in the younger generation. If set to 4, the ratio of two Survivor regions to one Eden region is 2:4, and one Survivor region accounts for 1 prime 6 of the whole young generation.

-XX:MaxPermSize=16m: set the persistent generation size to 16m.

-XX:MaxTenuringThreshold=0: set the maximum age of garbage. If set to 0, the younger generation will enter the older generation without going through the Survivor area. For more applications of the older generation, it can improve the efficiency. If you set this value to a large value, the younger generation object will be copied multiple times in the Survivor area, which can increase the survival time of the object in the younger generation and increase the overview of being recycled in the younger generation.

Recycler selection

JVM gives three choices: serial collector, parallel collector and concurrent collector, but serial collector is only suitable for small amount of data, so the choice here is mainly for parallel collector and concurrent collector.

By default, JDK5.0 used to use serial collectors, and if you want to use other collectors, you need to add the appropriate parameters at startup. After JDK5.0, JVM will judge based on the current system configuration.

Parallel collector with priority to throughput

As mentioned above, the parallel collector is mainly aimed at achieving a certain throughput and is suitable for science and technology and background processing. Typical configuration:

Java-Xmx3800m-Xms3800m-Xmn2g-Xss128k-XX:+UseParallelGC-XX:ParallelGCThreads=20

-XX:+UseParallelGC:** selects the garbage Scavenge collector as the parallel collector. This configuration is only valid for the younger generation. That is, in the above configuration, the younger generation uses concurrent Scavenge collection, while the older generation still uses serial collection.

-XX:ParallelGCThreads=20: configure the number of threads in the parallel collector, that is, how many threads perform garbage collection at the same time. This value is preferably configured equal to the number of processors.

Java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX:+UseParallelGC-XX:ParallelGCThreads=20-- XX:+UseParallelOldGC

-XX:+UseParallelOldGC: configure the old generation garbage collection method to collect in parallel. JDK6.0 supports parallel collection of older generations.

Java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX:+UseParallelGC-XX:MaxGCPauseMillis=100

-XX:MaxGCPauseMillis=100: sets the maximum time for each young generation garbage collection (in milliseconds). If this time cannot be satisfied, JVM will automatically resize the younger generation to meet this value. (the main adjustment is the Eden area, which reduces the amount of memory reclaimed in the Eden area, thus controlling the recovery time.)

Java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX:+UseParallelGC-XX:MaxGCPauseMillis=100-XX:+UseAdaptiveSizePolicy

-XX:+UseAdaptiveSizePolicy: when this option is set, the parallel collector automatically selects the size of the younger generation area and the corresponding Survivor area ratio to achieve the minimum corresponding time or collection frequency specified by the target system. This value is recommended to be turned on when using the parallel collector.

Concurrent collector with response time priority

As mentioned above, the main purpose of the concurrent collector is to ensure the response time of the system and reduce the pause time during garbage collection. It is suitable for application server, telecom and so on.

Typical configuration: java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX:ParallelGCThreads=20-XX:+UseConcMarkSweepGC-XX:+UseParNewGC

-XX:+UseConcMarkSweepGC: set the older generation to collect concurrently. After configuring this in the test, the configuration of-XX:NewRatio=4 failed for an unknown reason. Therefore, at this time, the size of the younger generation is best set with-Xmn.

-XX:+UseParNewGC: set the younger generation to collect in parallel. Can be used in conjunction with CMS collection. Above JDK5.0, JVM will be set according to the system configuration, so it is no longer necessary to set this value.

Java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX:+UseConcMarkSweepGC-XX:CMSFullGCsBeforeCompaction=5-XX:+UseCMSCompactAtFullCollection

-XX:CMSFullGCsBeforeCompaction: because the concurrent collector does not compress or clean up the memory space, it will produce "fragments" after running for a period of time, which reduces the running efficiency. This value sets how many times to run GC to compress and organize the memory space.

-XX:+UseCMSCompactAtFullCollection: turn on the compression of the older generation. May affect performance, but can eliminate fragmentation

-XX:GCTimeRatio: set the ratio of garbage collection time to total time, 010414K (130112K), 0.0650971 secs]

-XX:+PrintGCDetails

Output form:

[GC [DefNew: 8614K-> 781K (9088K), 0.0123035 secs] 118250K-> 113543K (130112K), 0.0124633 secs] [GC [DefNew: 8614K-> 8614K (9088K), 0.0000665 secs] [Tenured: 112761K-> 10414K (121024K), 0.0433488 secs] 121376K-> 10414K (130112K), 0.0436268 secs]

-XX:+PrintGCTimeStamps-XX:+PrintGC:

PrintGCTimeStamps can be mixed with the above two

Output form: 11.851: [GC 98328K-> 93620K (130112K), 0.0082960 secs]

-XX:+PrintGCApplicationConcurrentTime: prints the uninterrupted execution time of the program before each garbage collection. Can be mixed with the above

Output form: Application time: 0.5291524 seconds

-XX:+PrintGCApplicationStoppedTime: the time the program was paused during print garbage collection. Can be mixed with the above

Output form: Total time for which application threads were stopped: 0.0468229 seconds

-XX:PrintHeapAtGC: print detailed stack information before and after GC

Output form:

34.702: [GC {Heap before gc invocations=7: def new generation total 55296K, used 52568K [0x1ebd0000, 0x227d0000, 0x227d0000) eden space 49152K, 99% used [0x1ebd0000, 0x21bce430, 0x21bd0000) from space 6144K, 55% used [0x221d0000, 0x22527e10, 0x227d0000) to space 6144K, 0% used [0x21bd0000, 0x21bd0000, 0x221d0000) tenured generation total 69632K, used 2696K [0x227d0000, 0x26bd0000, 0x26bd0000) the space 69632K, 3% used [0x227d0000, 0x22a720f8, 0x22a72200, 0x26bd0000) compacting perm gen total 8192 K, used 2898K [0x26bd0000, 0x26bd0000, 0x273d0000) 0x273d0000 8192 K 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000) ro space 8192 K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000) rw space 12288K, 46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000) 34.735: [DefNew: 52568K-> 3433K (55296K), 0.0072126 secs] 55264K > 6615K (124928K) Heap after gc invocations=8: def new generation total 55296K, used 3433K [0x1ebd0000, 0x227d0000, 0x227d0000) eden space 49152K, 0% used [0x1ebd0000, 0x1ebd0000, 0x21bd0000) from space 6144K, 55% used [0x21bd0000, 0x21f2a5e8 0x221d0000) to space 6144K, 0% used [0x221d0000, 0x221d0000, 0x227d0000) tenured generation total 69632K, used 3182K [0x227d0000, 0x26bd0000, 0x26bd0000) the space 69632K, 4% used [0x227d0000, 0x22aeb958, 0x22aeba00, 0x26bd0000) compacting perm gen total 8192 K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000) the space 8192 K, 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000) ro space 8192 K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000) rw space 12288K, 46% used [used, 0x2b3d0000, 0x2b3d0000, 0x2b972060)}, 0.0757599 0x2b3d0000]

-Xloggc:filename: use in conjunction with the above to record relevant log information to a file for analysis.

Common configuration summary heap settings

-Xms: initial heap size

-Xmx: maximum heap size

-XX:NewSize=n: sets the size of the younger generation

-XX:NewRatio=n: sets the ratio of the younger generation to the older generation. For example, 3 means that the ratio of the young generation to the old generation is 1:3, and the young generation accounts for 1% of the sum of the young generation and the old generation.

-XX:SurvivorRatio=n: the ratio of Eden region to two Survivor regions in the young generation. Notice that there are two in the Survivor area. For example: 3, which means Eden:Survivor=3:2, and one Survivor area accounts for 1x5 of the whole younger generation.

-XX:MaxPermSize=n: sets the persistent generation size

Collector Settings

-XX:+UseSerialGC: set the serial collector

-XX:+UseParallelGC: sets the parallel Scavege collector

-XX:+UseParalledlOldGC: set parallel older generation collectors

-XX:+UseConcMarkSweepGC: sets the concurrent collector

Garbage collection statistics

-XX:+PrintGC

-XX:+PrintGCDetails

-XX:+PrintGCTimeStamps

-Xloggc:filename

Parallel Collector Settings

-XX:ParallelGCThreads=n: sets the number of CPU to use when collecting parallel Scavege collectors. Number of threads collected in parallel.

-XX:MaxGCPauseMillis=n: sets the maximum pause time for parallel collection

-XX:GCTimeRatio=n: sets the percentage of garbage collection time to program running time. The formula is 1 / (1cm n)

Concurrent Collector Settings

-XX:+CMSIncrementalMode: set to incremental mode. It is suitable for single CPU situation. -XX:ParallelGCThreads=n: the number of CPU used when the young generation of the concurrent collector is collected in parallel. Number of threads collected in parallel.

That's all for "what are the parameters commonly used in JVM performance tuning?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development