Java built-in performance monitoring tool: Monitoring and Management Console jconsole usage

Source: Internet
Author: User
Tags xms jconsole

Java built-in performance monitoring tool: Monitoring and Management Console jconsole usage
1. Would you like to verify whether some tuning parameters (such as Xms and Xmx) configured for the jvm work? Do you want to monitor the number of threads in your custom thread pool in real time? Is there a deadlock? Java. lang. OutOfMemoryError: Java heap space appears in the application. You know you need to adjust Xms and Xmx. Do you want to monitor the heap memory usage of your Java application in real time, and set the Xms, Xmx, and other parameters that best suit you according to the peak data? Java. lang. OutOfMemoryError: PermGen space appears in the application. You know you need to adjust XX: PermSize, XX: MaxPermSize. Do you want to find the peak value of PermGen in the permanent zone of your application, and set reasonable parameters such as XX: PermSize and XX: MaxPermSize according to it? We all know that the JVM heap memory is divided into young and old generations. The ratio of the old and young generations of JVM (that is, XX: NewRatio, the name is easy to confuse, that is, the young generation is older than the old generation) 2 (that is, the JVM heap memory is evenly divided into three portions, the annual boss occupies two portions, while the young generation occupies one portion. See Sun Java System Application Server Enterprise Edition 8.2 Performance Tuning Guide. This ratio is not suitable for all situations, especially when local variables in your Application are much larger than global variables, in addition, the lifecycle of a large number of local variables is very short. How to reasonably configure the ratio of the Young Generation (the sum of the Eden zone and the two middle vor zones) to the Old Generation (the Tenured zone) according to the real-time running status of the Application? XX: newRatio value?

Java built-in performance monitoring tool: Monitoring and Management Console jconsole, which provides real-time information about a Java process, such as memory, threads, class loading, jvm summary, and MBean, you may be able to provide reference for the above issues.

 

2. Before starting jconsole, let's review some JVM parameters:
-Xms initial/minimum heap memory size-Xmx maximum heap memory size-Xmn young generation size-XX: NewSize young generation size-XX: MaxNewSize young generation maximum-XX: newRatio ratio of the old generation to the young generation-XX: MaxPermSize permanent generation maximum value-XX: PermSize permanent generation initial value some materials say that Xms and Xmx are set to the JVM memory size, which is incorrect, in addition to the heap memory reserved for developers, the JVM also has non-heap memory.

Readers may find that there are three ways to divide the young generation size:-Xmn mode,-XX: NewSize +-XX: MaxNewSize mode, and-XX: NewRatio mode. All three options are available. The priorities are-XX: NewSize +-XX: MaxNewSize,-Xmn, and-XX: NewRatio, that is to say, after the previous priority is configured, it will be overwritten.

 

3. Enable jconsole on the local machine to monitor the Java Process CMD and switch to the % JAVA_HOME %/bin directory, and directly execute jconsole


You can open the Java Monitoring and Management Console:


The local process list shows all Java processes in local execution. Double-click the process you are interested in (for example, the PID is 8504) to monitor the process:


 

4. to remotely monitor a Java Process, you must enable JMX when starting it.
Take tomcat on the remote host as an example. First, find an available remote port for jmx, such as 9999:


No news is good news ~ Add the following configuration before the % atat_home %/bin/catalina. sh file:
JAVA_OPTS=-Xms1024m -Xmx2048m -XX:MaxPermSize=128m -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false





Restart tomcat, open the Java Monitoring and Management Console on the local machine, and enter the remote host name and jmx port number for the remote process:


Click the connect button to monitor tomcat on the remote host in real time:


 

5. Take a look at some useful information provided by jconsole in step 1.
5.1. Check whether the JVM setting information works. Click the VM overview and you can see that some of the JAVA_OPTS parameters we just set have already worked:


5.2. is real-time monitoring of the tomcat thread pool and the number of custom thread pools still worrying about the mystery of the tomcat thread pool? Are you still worried about the black box of your own thread pool? Let's see:


Our tomcat just started, we can see from there is only one http-8080-Acceptor-0 thread, we go to access our project, and then come back to look at it:


Http-8080 threads suddenly increased to 8. Is everything clear and under control?
5.3. For actual memory usage consumption, click the Java Monitoring and Management Console memory leaf item to view the usage of tomcat heap memory:


There are many options in the chart:


Let's take a look at the Eden area:


The Eden area is similar to the overall heap memory trend. Let's look at the region vor:


The trend of the VOR region is relatively stable in a short period of time. Let's look at the Old Gen area again:


This trend is more stable, and compared with the two charts of the region VOR and the Old Gen area, we can clearly see that at about, a batch of objects were moved from the region vor area to the Old Gen area. Finally, let's look at the Perm Gen zone.
This trend is most stable. We can see that some new static resources such as class are loaded into JVM when we visit our project at around. The graph of the number of loaded classes in 5.4 also confirms this point.
5.4. tomcat loading class

 

6. Use with jmap

First find that the PID of our tomcat process is 13863, and then execute jmap-heap 13863:


The columns in Heap Configuration are basically the ones we Just configured. For example, MaxHeapSize is 2048 MB and MaxPermSize is 128 MB. This is the same as that in 5.1.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.