Some records on Java performance monitoring

Source: Internet
Author: User
Tags jconsole

All the content in this article is based on JDK 5, which may be different if JDK 6 is used.
In the past few days, we have done some performance monitoring work, some of which are worth recording:
JDK itself provides many tools based on command lines and guis. It is very useful to learn to apply them rationally.
Jmap is a command line program that is used to view the number of objects in the JVM. directly input jmap to display the usage. The following are two common functions: jmap-histo 'jvmpid'> memory.txt


Among them, jvmpidis the System ID number of the current virtual machine. After waiting, memory.txt will save the existing object types in the running of the current virtual machine in a descending order of space usage. We can see which types of objects occupy a large amount of space and generate a large number of objects, this function is useful, especially when a problem occurs with a custom object and the user cannot be recycled in a timely manner. Jmap-heap: format = B 'jvmpid'

Different from the above, a text file is generated, and a binary snapshot file is generated here. You can use the corresponding analysis software to enable it for more comprehensive functional detection, for example, eclipse memory analyzer.
Note that the above snapshot Export command takes about 1 minute to wait for about 1 GB of JVM memory, and the JVM will be suspended during execution, therefore, do not use the system during peak hours or critical hours.
Next is jstat, which is also a command line program used to view the usage of each JVM memory and GC. There are many usage and parameters. There are two functions we use: jstat-gcutil 'jvmpid'

The GC status will be displayed. ygc and FGC represent the number of small GC and large GC, and ygct and fgct represent the time occupied by small GC and large GC. Normally, the number of large GC times should be much smaller than that of small GC. For example, my current system has had 10 million small GC times, and the large GC has only 50 times, which is a good performance in programming. Jstat-gccapacity 'jvmpid'

The memory usage of GC is displayed at the moment. The result structure is similar to that of the previous command, and there is also a problem. The data displayed is not very intuitive. It would be much better to view it through the GUI.

JVM comes with the GUI monitoring status function. In jdk5, we need to make some configurations to manually enable it. First, we need to add some attributes to the JVM startup Item, suppose our system is a project running under the Tomcat container, we can modify the java_opts variable to enable the monitoring service java_opts = "$ java_opts-DCOM. sun. management. jmxremote-DCOM. sun. management. jmxremote. port = 12345-DCOM. sun. management. jmxremote. SSL = false"

This will enable the JMX-based Remote Monitoring Service. In this configuration method, the default authentication mechanism is also enabled. We also need to set permissions elsewhere, the user name and password can be used to log on. Let's put aside the rest of the work on the server and talk about the client.

We need a GUI client access tool to remotely view the information of this virtual machine. JDK 5 comes with a client named jconsole. You can find it in the bin folder of the JDK directory and double-click it to run it, click the "remote" tab and enter the remote IP address, port, user name, and password. If the server is configured properly, access is successful.

Back on the server side, we also need to configure the JVM remote user name and password. Modify the $ java_home/JRE/lib/management/jmxremote. Access and jmxremote. Password. template files.

First, directly modify the jmxremote. Access File, cancel the comments of the last two usernames, and change to monitorrole readonly.
Controlrole readwrite \
Create javax. Management. Monitor. *, javax. Management. Timer .*\
Unregister

The difference between the two users is obvious. You can cancel one.
Modify the jmxremote. Password. template file name and change it to jmxremote. Password. Then, edit the last two lines of users and change the password to what you want.
Next, you need to change the permission of the jmxremote. Password File to readable and writable chmod 600 $ java_home/JRE/lib/management/jmxremote. Password.

At this point, you need to change 127.0.0.1 in the/etc/hosts file to your real Internet IP address, such as 210.209.83.37, the IP address returned by running the hostname-I command should also be 210.209.83.37. After each modification, the monitoring service will take effect after the JVM is restarted.
After JVM is enabled, run the jconsole client and enter the IP port, user name and password. The user name is monitorrole or controlrole or your custom one (with different permissions ).
You can also skip the user verification section and just add-DCOM. sun. management. jmxremote. authenticate = false. You can also modify COM. sun. management. jmxremote. password. file and COM. sun. management. jmxremote. access. the location of the file custom permission file and password file, but this is not necessary.
After successful logon, all information on the GUI can be learned and accepted intuitively. However, we still need to have some JVM knowledge, especially for GC, if you have the opportunity, we will continue to explain it in future documents.

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.