JVM tuning tool details

jmap

        It is used to view memory information, number of instances and occupied memory size.

jmap -histo <process_id>      

        num: serial number

        Instances: number of instances

        bytes: occupied space

        Class name: class name, C = char[], S = short[], I = int []

jmap -heap <process_id>

        View heap information

jmap -dump:format=b,file=<filename> <process_id>

        dump heap memory. You can add parameters at startup and save a snapshot of heap memory when OOM occurs:

        1. -XX:+HeapDumpOnOutOfMemoryError

        2. -XX:HeapDumpPath=./

        You can import the dump file for analysis using the jvisualvm command tool.

jstack

        Use jstack plus process id to find deadlocks.

public class DeadLockTest {
    private static Object lock1 = new Object();

    private static Object lock2 = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lock1) {
                try {
                    System.out.println("Thread1 begin");
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (lock2) {
                    System.out.println("Thread1 end");
                }
            }
        }).start();

        new Thread(() -> {
            synchronized (lock2) {
                try {
                    System.out.println("Thread2 begin.");
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (lock1) {
                    System.out.println("Thread2 end.");
                }
            }
        }).start();
        System.out.println("Main Thread end.");
    }
}

          Judge deadlock         

 

 

Connect to the JVM remotely

java ‐Dcom.sun.management.jmxremote.port=8888 ‐Djava.rmi.server.hostname=192.168.50.60 ‐Dcom.sun.management.jmxremot e.ssl=false ‐Dcom.sun.management.jmxremote.authenticate=false ‐jar microservice‐eureka‐server.jar

PS: - Dcom.sun.management.jmxremote.port is the JMX port of the remote machine                       -  Djava.rmi.server.hostname is the IP address of the remote machine

JMX configuration for Tomcat

The last Java in the catalina.sh file_ Add the following configuration line under the assignment statement of opts  

JAVA_OPTS="$JAVA_OPTS ‐Dcom.sun.management.jmxremote.port=8888 ‐Djava.rmi.server.hostname=192.168.50.60 ‐Dcom.sun.ma nagement.jmxremote.ssl=false ‐Dcom.sun.management.jmxremote.authenticate=false"

jinfo

        View the extension parameters of a running Java application.

jinfo -flags <process_id>

        View JVM parameters

 jinfo -sysprops <process_id>

        View Java system parameters

 

 jstat

        jstat can view the usage of various parts of heap memory and the number of loaded classes.

        jstat [- command options] [vmid] [interval (MS)] [number of queries]

jstat -gc <process_id>

        Program memory usage and GC pressure can be evaluated.

  S0C: the size of the first surviving area, unit KB S1C: the size of the second surviving area S0U: the use size of the first surviving area S1U: the use size of the second surviving area EC: the size of Eden Park EU: the use size of Eden Park OC: the old age size OU: the old age use size MC: the method area size (meta space) MU: usage size of method area CCSC: compressed space size CCSU: usage size of compressed space YGC: times of garbage collection of the younger generation YGCT: time consumption of garbage collection of the younger generation, unit s FGC: times of garbage collection in the old age FGCT: time consumption of garbage collection in the old age, unit s GCT: total time consumption of garbage collection, unit s

jstat -gccapacity <process_id>

  NGCMN: Cenozoic minimum capacity NGCMX: Cenozoic maximum capacity NGC: current Cenozoic capacity S0C: size of the first surviving area S1C: size of the second surviving area EC: size of Eden Park OGCMN: old age minimum capacity OGCMX: old age maximum capacity OGC: current old age size OC: current old age size MCMN: minimum metadata capacity MCMX: maximum metadata capacity MC: current metadata space size CCSMN: minimum compressed class space size CCSMX: maximum compressed class space size CCSC: current compressed class space size YGC: younger generation GC times FGC: older generation GC times

Tags: Java

Posted on Fri, 12 Nov 2021 05:13:18 -0500 by pukstpr12