Data area settings
- Xms: Initial heap size
- Xmx: Maximum heap size
- Xss: Stack size per thread in Java
- XX: NewSize=n: Set Younger Generation Size
- XX: New Ratio = n: Set the ratio of the younger generation to the older generation. For example, the ratio of the young generation to the old generation is 1:3, and the young generation accounts for 1/4 of the whole young generation and the old generation.
- XX: SurvivorRatio=n: The ratio of Eden area to two Survivor areas in the younger generation. Note that there are two Survivors. For example: 3, that means Eden: Survivor=3:2, a Survivor area accounts for 1/5 of the whole young generation.
- XX: MaxPermSize=n: Set the persistent generation size.
Collector settings
- XX:+UseSerial GC: Setting up Serial Collector
- XX:+UseParallel GC:: Setting up Parallel Collector
- XX:+UseParalledlOldGC: Setting up Parallel Aged Collector
- XX:+UseConcMarkSweepGC: Setting up Concurrent Collector
- XX:+UseG1GC:G1 collector, Java 9 opens by default, no settings required
Note: Server jvm parameter tuning is portable - ---->: https://blog.csdn.net/Vincent 2014 Linux/article/details/90211192
Common tools provided by JVM
1. jps: Used to display local Java processes, you can view several Java programs running locally and display their process numbers.
Command format: jps
2. jinfo: Running environment parameters: Java System properties and JVM command line parameters, Java class path and other information.
Command format: jinfo process pid
3. jstat: A command-line tool for monitoring various running status information of virtual machines.
Command format: jstat-gc 123 250 20
4. jstack: You can observe the current state of all threads in the JVM.
Command format: jstack process pid
5. jmap: Observe the occupancy of the physical memory of the running JVM (e.g. which objects are generated and the number of them).
Command format: jmap [option] pid
- dump:[live,]format=b,file = uses hprof binary form to output the heap content of jvm to the file. The live sub-option is optional. If the live option is specified, only the live object is output to the file.
- finalizerinfo prints information about objects awaiting recycling.
- heap prints the summary information of heap, the algorithm used by GC, the configuration of heap and the usage of wise heap.
- His [: live] prints the number of instances of each class, memory footprint, class full name information. VM's internal class name begins with a prefix "*". If live sub-parameters are added, only the number of live objects is counted.
-permstat prints the class load and jvm heap persistence layer information, including the name, liveness, address, parent classloader and the number of loaded classes of each classloader. In addition, the number of internal strings and the number of occupied memory will also be printed out.
Use example: jmap-heap 27900 # shows the whole heap information of pid as follows:
[root@localhost ~]# jmap -heap 27900 Attaching to process ID 27900, please wait... Debugger attached successfully. Client compiler detected. JVM version is 20.45-b01 using thread-local object allocation. Mark Sweep Compact GC Heap Configuration: #Heap memory initialization configuration MinHeapFreeRatio = 40 #- XX: MinHeap FreeRatio Sets the Minimum Free Ratio of JVM Heap MaxHeapFreeRatio = 70 #- XX: MaxHeap FreeRatio Sets the Maximum Free Ratio of JVM Heap MaxHeapSize = 100663296 (96.0MB) #- XX:MaxHeapSize = Set the maximum size of the JVM heap NewSize = 1048576 (1.0MB) #- XX:NewSize = Sets the default size of'Cenozoic'for the JVM heap MaxNewSize = 4294901760 (4095.9375MB) #- XX:MaxNewSize = Set the maximum size of the'Cenozoic'of the JVM heap OldSize = 4194304 (4.0MB) #- XX:OldSize = Size of'Old Generation'setting JVM heap NewRatio = 2 #- XX: New Ratio=:'Cenozoic'and'Old' size ratios SurvivorRatio = 8 #- XX:SurvivorRatio = Set the size ratio of Eden area to Survivor area in the younger generation PermSize = 12582912 (12.0MB) #- XX: PermSize=<value>: Set the initial size of the'persistence'of the JVM heap MaxPermSize = 67108864 (64.0MB) #- XX: MaxPermSize=<value>: Set the maximum size of the'persistent generation'of the JVM heap Heap Usage: New Generation (Eden + 1 Survivor Space): #The Cenozoic region contains Eden+1 Survivor region. capacity = 30212096 (28.8125MB) used = 27103784 (25.848182678222656MB) free = 3108312 (2.9643173217773438MB) 89.71169693092462% used Eden Space: #Existence Distribution in Eden Area capacity = 26869760 (25.625MB) used = 26869760 (25.625MB) free = 0 (0.0MB) 100.0% used From Space: #Memory distribution in one of the Survivor areas capacity = 3342336 (3.1875MB) used = 234024 (0.22318267822265625MB) free = 3108312 (2.9643173217773438MB) 7.001809512867647% used To Space: #Memory distribution in another Survivor area capacity = 3342336 (3.1875MB) used = 0 (0.0MB) free = 3342336 (3.1875MB) 0.0% used tenured generation: #Current memory distribution in Old region capacity = 67108864 (64.0MB) used = 67108816 (63.99995422363281MB) free = 48 (4.57763671875E-5MB) 99.99992847442627% used Perm Generation: #Current'persistent generation'memory distribution capacity = 14417920 (13.75MB) used = 14339216 (13.674942016601562MB) free = 78704 (0.0750579833984375MB) 99.45412375710227% used
Anomaly detection
-
Over-occupied CPU resources
1. top looks at the current CPU situation and finds the process PID=123 that occupies too much CPU.
2. Top-H-p123 finds two threads with high CPU usage, and records that PID=2345, 3456 is converted to hexadecimal.
3. jstack-l 123 > temp.txt prints out the thread stack of the current process.
4. Find two thread run stacks corresponding to the second step and analyze the code. -
OOM anomaly detection
1. Use top instruction to query server system status.
2. ps-aux | grep Java finds the PID of the current Java process.
3. jstat-gcutil PID interval to view the current status of GC.
4. jmap-histo: live PID can be used to count the distribution of live objects, from high to low to view the objects occupying the most memory.
5. jmap-dump: format = b, file = filename [pid] uses Jmap dump.
6. Use performance analysis tools to analyze the files from dump, such as MAT.