Local tuning

jvisualvm
Copy the code

Open the VisualVM tool that comes with the JDK to see what each project looks like.

The command line jstat

jstat -gcutil  pid 1000
Copy the code

The command line jmap

Jmap-heap pid Jmap-histo :live PID Jmap-heap pid Jmap-histo :live PID Jmap-heap pid Jmap-histo :live PIDCopy the code

The results of

Parallel GC with 4 thread(s) MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 MinHeapFreeRatio = 0 -xx :MaxHeapFreeRatio Sets the maximum heap free ratio of the JVM (default 70) MaxHeapSize = 2082471936 (1986.0MB) // The JVM startup parameter -xx :MaxHeapSize= set the maximum size of the JVM heap NewSize= 1310720 (1.25MB)// The JVM startup parameter -xx :NewSize= set the default size of the 'new generation' of the JVM heap MaxNewSize = 17592186044415 MB// Corresponding JVM startup parameter -xx :MaxNewSize= Sets the maximum size of the JVM heap 'new generation' OldSize = 5439488 (5.1875MB)// The corresponding JVM startup parameter -xx :OldSize=<value>: Sets the size of the old generation of the JVM heap NewRatio= 2 // The corresponding JVM startup parameter -xx :NewRatio=: the size ratio of the new generation to the old generation SurvivorRatio= 8 // Corresponding JVM startup parameter -xx :SurvivorRatio= set size ratio of Eden zone to Survivor zone in young generation PermSize = 21757952 (20.75MB) // Corresponding JVM startup parameter -xx :PermSize=<value>: Sets the initial size of the immortal generation of JVM heap MaxPermSize = 85983232 G1HeapRegionSize = 0 (0.0MB) Heap Usage:// Heap memory Usage PS Young Capacity = 33030144 (31.5MB)// Total Eden capacity Used = 1524040 (1.4534378051757812MB) Free = 31506104 (30.04656219482422MB) // Remaining capacity in Eden 4.614088270399305% Capacity = 5242880 (5.0MB) Used = 0 (5.0MB) Free = 5242880 (5.0MB) 0.0% used To Space: Capacity = 5242880 (5.0MB) Used = 0 (0.0MB) Free = 5242880 (5.0MB) 0.0% Used PS Old Generation Capacity = 86507520 (82.5MB) Used = 0 (0.0MB) Free = 86507520 (82.5MB) 0.0% Used PS Perm Generation// Current memory Capacity = 22020096 (21.0MB) Used = 2496528 (2.3808746337890625MB) Free = 19523568 (18.619125366210938MB) 11.337498256138392% Used 670 interned Strings evicted 43720 bytes.Copy the code

review

  1. If the program is out of memory or frequentGC, there is a good chance of a memory leak, and in this case, the Java heapDumpView the status of the object.
  2. To make the heapDumpYou can use it directlyjvmbuilt-injmapCommand.
  3. You can use it firstjmap -heapCommand to view heap usage to see how much space each heap is using.
  4. usejmap -histo:[live]View objects in heap memory. If a large number of objects are continually referenced and not released, then there is a memory leak and the code needs to be combined to release unused objects.
  5. You can also usejmap -dump:format=b,file=<fileName>The jhat command saves the heap information to a file and views the details with the jhat command.
  6. This parameter is recommended when memory leaks, overflow, or other conditions occurdumpSeveral times in memory, the memory files are numbered and archived for subsequent memory analysis.