Java JVM: virtual machine performance monitoring, troubleshooting tools (3)

1. Basic troubleshooting tools

  • JMC (Java Mission Control) and JFR (Java Flight Recorder)
    • JMC has been included in the JDK since Java7, and it can be started by directly typing jmc
    • Before using it, you need to configure the Java process to support JMX connection, and add the configuration at startup
      • -Dcom.sun.management.jmxremote.port=7091
      • -Dcom.sun.management.jmxremote.authenticate=false
      • -Dcom.sun.management.jmxremote.ssl=false
    • Unlock the commercial function and open the flight record configuration (choose one)
      • jcmd pid VM.unlock_commercial_features
      • -XX:+UnlockCommercialFeatures -XX:+FlightRecorder

insert image description here

  • jps : Java Virtual Machine Process Status Tool virtual machine process status tool
    • Syntax: jps [options] [hostid]
      • -q: only output PID
      • -m: output the parameters passed to the main method
      • -l: full package name or full pathname of the application JAR file
      • -v: View the specified parameter list when the virtual machine starts
    • Can list the running virtual machine processes, and display the virtual machine execution main class name and the local virtual machine unique ID of these processes
    • You can also query the process status of the remote virtual machine with the RMI service enabled through the RMI protocol. The parameter hostid is the host name registered in the RMI registry

insert image description here

  • jstat: virtual machine statistics monitoring tool
    • A command-line tool for monitoring various running status information of virtual machines
    • Can display runtime data such as class loading, memory, garbage collection, and even compilation in the virtual machine process
    • example
      • Query the garbage collection status of process 2764 every 250 milliseconds, a total of 20 queries
      • jstat -gc 2764 250 20
      • The query results show that the new generation Eden area (E) used by 2764 uses 6.2% of the space, the two Survivor areas (S0, S1) are empty, and the old generation (O) and the permanent generation use 41.42% and 47.20% of the space respectively , MinorGC (YGC) 16 times, time-consuming (YGCT) 0.105 seconds, Full GC (FGC) 3 times, time-consuming (FGCT) 0.472 seconds, total time-consuming of all GC (GCT) 0.577 seconds

insert image description here

  • jinfo: Java configuration information tool
    • View and adjust various parameters of the virtual machine in real time
  • jmap: Java memory mapping tool
    • Generate a heap dump snapshot, and you can also query the details of the finalize execution queue, Java heap, and method area
  • jhat: virtual machine heap dump snapshot analysis tool
    • Use with jmap to analyze the heap dump information generated by jmap
    • Typically not directly analyzed on the server where the application is deployed
  • jstack: Java stack trace tool
    • Generate a thread snapshot at the current moment of the virtual machine, which is used to locate the reason for the long pause of the thread

2. Visual troubleshooting tool

  • JHSDB: A Service Agent-Based Debugging Tool
  • JConsole: Java monitoring and management console
  • VisualVM: poly-fault handling tool
  • Java Mission Control: Continuous Online Monitoring Tool

3. Other fault related

  • Program Deployment Strategy on Large Memory Hardware
    • Main deployment methods of monolithic applications on hardware with large memory
      • Manage a large amount of Java heap memory through a single Java virtual machine instance
        • Long pauses caused by reclaiming large chunks of heap memory
        • Large memory must have the support of 64-bit Java virtual machine
        • It is necessary to ensure that the application is stable enough to generate large-capacity snapshot files in the event of heap memory overflow
        • The same program generally consumes more memory in a 64-bit virtual machine than in a 32-bit virtual machine
      • Simultaneously use several Java virtual machines to establish logical clusters to utilize hardware resources
        • Nodes compete for global resources, most typically disk competition
        • It is difficult to utilize certain resource pools, such as connection pools, most efficiently
        • Node is inevitably limited by 32-bit memory, each process can only use 2GB of memory
        • Heavy use of local cache
  • Memory overflow caused by inter-cluster synchronization
  • Overflow error caused by off-heap memory
    • Java off-heap memory limit
      • Direct memory: resizable via -XX:MaxDirectMemorySize
      • Thread stack: can be resized by -Xss, and StackOverflowError is thrown due to insufficient memory
      • Socket buffer area: each Socket connection has Receive and Send two buffer areas
      • JNI code: If the code uses JNI to call the native library, the memory used by the native library is not in the heap
      • Virtual machine and garbage collector: need to consume a certain amount of memory when doing work
  • External commands slow down the system
  • Server virtual machine process crashes
  • Improper data structure leads to excessive memory usage
  • Long pauses caused by Windows virtual memory
  • Long pauses caused by safepoints

Guess you like

Origin blog.csdn.net/baidu_40468340/article/details/128548313