In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are Java JVM tuning skills". In daily operation, I believe many people have doubts about Java JVM tuning skills. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are Java JVM tuning skills?" Next, please follow the editor to study!
1. When do you need JVM tuning
Slow response and high CPU usage of applications
The application throughput is small and takes up too much memory space
These appearances are generally accompanied by frequent garbage collection, or OOM.
What is the general tuning of 2.JVM tuning
Memory occupied by the application (heap memory, meta-space memory)
The size and proportion of the new generation and the old age.
The choice of garbage collector.
Heap memory parameters
| |-Xms512m | initial heap size |
Default value: if it is not set, the initial value will be the sum of the memory of the older and younger generations-Xmx1024m
Memory related parameters of younger generation
|-Xmn512m | initial and maximum values of the new generation.
The default value is 1x4 of heap memory (1x4 of allocated heap memory). -XX:NewSize=512m-XX:MaxNewSize=512m-XX:NewRatio=8
For example:-XX:NewRatio=8
Means: old memory: younger memory = 8:1 |
| |-XX:SurvivorRatio=8 | ratio of Cenozoic generation to survival area |
-XX:SurvivorRatio=8
Indicates the survival area: new generation = 1:8 = "the new generation accounts for 8x10 of the younger generation, and each survival area accounts for 1x10 of the younger generation |
Meta-space parameter
| |-XX:MetaspaceSize | initial meta-space size |
Reaching this value triggers garbage collection for type unloading-the basic steps of XX:MaxMetaspaceSize=256m3.JVM tuning
First of all, when starting the program,
Add parameters related to GC log-XX:+PrintGC: output GC log-XX:+PrintGCDetails: output detailed log of GC-XX:+PrintGCTimeStamps: output timestamp of GC (in the form of base time)-XX:+PrintGCDateStamps: output timestamp of GC (in the form of date For example, 2018-08-29T19:22:48.741-0800)-XX:+PrintHeapAtGC: print out heap information before and after GC-Xloggc:gc.log: output path of log file 3.2 add memory overflow and pre-Full gc snapshot output parameters-generate heapdump file when memory overflow occurs in XX:+HeapDumpOnOutOfMemoryError-generate heapdump file before Full gc occurs in XX:+HeapDumpBeforeFullGC-XX:HeapDumpPath: specify heapdump output path 3.3.1Hap memory is insufficient by log
Troubleshoot whether the set heap memory is too small or if there is a memory overflow.
Get the memory snapshot at that time, use tools to analyze jump, use Mat tools to analyze.
3.3.2 frequent Full gc
Consider whether it is a new online code problem, there is a large object occupation, resulting in frequent YGC, which leads to an increase in the number of objects promoted to the older generation, and the old age reaches the memory threshold to trigger Full gc
Consider whether the new generation setting is too small.
Summary:
If there is a code problem, you can find the changed code through the version control tool and optimize the code.
If it is not a code problem, you can appropriately increase the heap memory size, the size and proportion of the new generation and the old age, and appropriately increase the size of the new generation memory.
4. Monitoring tool 4.1Using jstat to count gc related information
Jstat is a built-in tool under jdk bin, which is mostly used to count gc-related information. The steps are as follows.
Get the process number ps-ef | grep corresponds to the process
For example, if I want to count the gc information of jvm-demo.jar (process number 27164) and count it every 3 seconds, I can execute the following command
Jstat-gcutil 27164 3000
Mainly focus on the following.
S0, S1: indicates the percentage of usage of the two survior regions
Percentage of e:eden area usage
O: percentage used in the old years
Percentage of m:metaspace (metadata space) usage
Ygc: the number of gc of the new generation
Ygct: total cumulative time of the new generation gc
Number of fgc:full gc
Total cumulative time of fgct:full gc
Total cumulative time of gct:gc
To further view the last GC information
Jstat-gccause 27146 3000
LGCC: the reason for the last gc, Allocation Failure is full of new generations, so gc
Gcc: the reason for the current gc. If there is no gc, no gc.
4.2 use the jmap command to check the JVM heap information at a certain time
Use steps
Get the corresponding process for pid ps-ef | grep
For example, if I want to count the information of jvm-demo.jar (process number 27164) and count it every 3 seconds, I can execute the following command
Jmap-heap 2865
Example of output:
Attaching to process ID 27146 Configuration information related to please wait...Debugger attached successfully.Server compiler detected.JVM version is 25.144-b01using thread-local object allocation.Mark Sweep Compact GC# heap Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 104857600 (100.0MB) NewSize = 10485760 (10.0MB) MaxNewSize = 34930688 (33.3125MB) OldSize = 20971520 ( 20.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) # configuration information related to heap occupancy Heap Usage:New Generation (Eden + 1 Survivor Space): capacity = 12517376 (11.9375MB) used = 10708296 (10.212226867675781MB) free = 1809080 (1.7252731323242188MB) 85.54745020042539% usedEden Space: capacity = 11141120 (10.625MB) used = 10708272 (10.212203979492188MB) free = 432848 (0.4127960205078125MB) 96.11486098345588 usedFrom Space: capacity = 1376256 (1.3125MB) used = 24 (2.288818359375E-5MB) free = 1376232 (1.3124771118164062MB) 0.001743861601428572 usedTo Space: capacity = 1376256 (1.3125MB) used = 0 (0.0MB) free = 1376256 ( 1.3125MB) 0.0% usedtenured generation: capacity = 27684864 (26.40234375MB) used = 27096504 (25.84123992919922MB) free = 588360 (0.5611038208007812MB) 97.87479541167332% used15431 interned Strings occupying 2044328 bytes.5. What are the common tuning tools?
JDK built-in command line: jps (view jvm process information), jstat (to monitor the running status of jvm, such as gc, jvm memory, class loading, etc.), jinfo (to view jvm parameters, can also be dynamically adjusted), jmap (generate dump files, which will affect online services when dump), jhat (analysis of dump, but generally put dump export to mat for analysis), jstack (view thread).
JDK built-in visual interfaces: JConsole, VisualVM, these two are very useful in the QA environment pressure testing.
Alibaba's open source arthas: artifact, online tuning is very convenient, installation and display effect is very friendly
At this point, the study of "what are the Java JVM tuning skills" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.