Java self-contained performance monitoring tool: monitoring and management Console Jconsole use

Source: Internet
Author: User
Tags xms jconsole

1. Preface
    • Want to verify that you have some tuning parameters (such as Xms, XMX, etc.) that you have with the JVM?
    • Do you want to monitor the number of threads in the actual runtime of your custom thread pool in real time, with or without deadlocks?
    • Application appears Java.lang.OutOfMemoryError:Java heap space, you know need to adjust Xms, Xmx. Want to monitor the heap memory usage of your Java application in real time and set the parameters that are best for your Xms, XMX, etc. based on data such as spikes?
    • Application appears java.lang.OutOfMemoryError:PermGen space, you know need to adjust xx:permsize, xx:maxpermsize. Want to find the peak usage of your application's permanent zone PermGen, and set reasonable xx:permsize, xx:maxpermsize parameters according to it?
    • As we all know, JVM heap memory is divided into younger generations and older generations. The ratio of the old generation of the JVM to the younger generation (ie, xx:newratio, the name is confusing, that is, the younger generation than the old Generation) is 2 (that is, the JVM heap memory is divided evenly into three parts, the eldest brother occupies two, and the younger generation occupies a copy. Reference 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 far greater than the global variables, and a large number of local variables have a short life cycle. How to reasonably configure the proportion xx:newratio values of the young generation (youth Generation, the sum of the Eden and the two Survivor zones) and the old Generation, or tenured area, based on the real-time operation of the application?

Java comes with performance monitoring tools: monitoring and Management Console jconsole, which can provide real-time information about the memory, threads, class loading, JVM profiles, and MBean of a Java process, and may be able to provide references to the above issues.


2. JVM some parameters before starting Jconsole Let's review some of the main parameters of the JVM:
    • -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 value
    • -xx:newratio the ratio of old generation to younger generation
    • -xx:maxpermsize maximum value for persistent generations
    • -xx:permsize Persistent Generation initial value
Some sources say that Xms, XMX set the JVM memory size, is not right, the JVM in addition to the developer to use the heap memory and non-heap memory.

Readers may find that there are three ways to divide younger generations:-xmn,-xx:newsize +-xx:maxnewsize,-xx:newratio. Three kinds can be, priority from high to low in order is-xx:newsize +-xx:maxnewsize mode,-xmn mode,-xx:newratio mode, that is, the configuration of the previous high priority is covered out.


3. Native enable Jconsole to monitor Java process cmd switch to%java_home%/bin directory, directly execute Jconsole


To open the Java monitoring and management console:


The local process list shows all the Java processes in the local execution, and the process can be monitored by double-clicking on the process you are interested in (for example, the PID is 8504):



4. Remote monitoring Java process to remotely monitor the Java process, you need to enable JMX when you start it.
Take Tomcat on the remote host, for example, to find an available remote port for JMX, such as 9999:


No News is good news~ in front of the%tomcat_home%/bin/catalina.sh file with the following configuration:
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 "





Then restart Tomcat, open the Java monitoring and management console in the native computer, and remote process enter the remote host name and the JMX port number:


By tapping the "Connect" button, you can monitor Tomcat on the remote host in real time:



5. Some useful information provided by Jconsole then the case of the 4th step is looked down.
5.1. JVM setting information Whether it works check click on "VM profile" to see some of the parameters of the java_opts we've just set up have worked:


5.2. Tomcat thread pool, number of custom thread pools real-time monitoring is still a headache for the tomcat thread pool? Still in the definition of the thread pool "black box" general and distressed? Look:


Our tomcat just started, and as we can see there is only one http-8080-acceptor-0 thread, we go to visit our project and then come back to see:


The http-8080 thread grew to 8 at a sudden. Is everything at a glance, under control?
5.3. Memory usage Actual consumption Click the Java monitoring and management console memory leaf entry to see the use of Tomcat heap memory:


There are many options in the chart:


Let's take a look at the Eden area:


The Eden area is basically the same as the whole heap memory. See Survivor District again:


The Survivor area has a relatively stable trend in a short period of time. Look at the old Gen area again:


This trend is more stable, and compared to the Survivor area, Old Gen District two graphs, it is clear that at about 19:58 at that time there are a number of objects moved from the Survivor area to the old Gen area. Last look at Perm Gen district.
This trend is the most stable. It can be seen that at about 19:58, when we visited our project, some static resources such as new classes were loaded into the JVM. This is also confirmed by a graph of the number of loaded classes in 5.4.
5.4. Tomcat Load class case


6. With the use of Jmap

Find us first the PID of the Tomcat process is 13863 and then execute jmap-heap 13863:


The basic of the Heap Configuration is the ones we just match, such as Maxheapsize is 2048 mb,maxpermsize is MB. This is the same as in 5.1.


Resources
    • Sun Java System Application Server Enterprise Edition 8.2 Performance Tuning Guide
    • Frequently asked Questions about the Java HotSpot VM

Java self-contained performance monitoring tool: monitoring and management Console Jconsole use

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.