In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you an example of Java performance monitoring analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
A few days ago, we did some performance monitoring work, and there are some things worth recording:
JDK itself provides a lot of tools, based on both the command line and GUI, and it is useful to learn to use them properly.
The first is jmap, which is a command line program that is used to view the number of objects in JVM. Entering jmap directly shows the usage. Here are two common functions:
Java code
Jmap-histo 'jvmPid' > memory.txt
JvmPid is the system ID number of the current virtual machine process. After waiting, memory.txt will save the object types that exist in the current virtual machine operation in the order from the largest to the smallest. From this, we can see which types of objects take up more space and generate a large number, especially when the custom objects cannot be recycled in time due to problems with custom objects. This function is very useful.
Java code
Jmap-heap:format=b 'jvmPid'
Unlike the above, a text file is generated, and a binary snapshot file is generated here, which can be opened with the appropriate analysis software for more comprehensive detection, such as Eclipse Memory Analyzer.
It should be noted that the above export snapshot command, in the case of about 1 GB of JVM memory, needs to wait for about 1 minute, and the execution of JVM will be suspended during execution, so do not use it during the peak period or critical time of the official running system.
Then there is jstat, which is also a command line program, which is used to view the various memory and GC usage of JVM. There are a lot of usage and parameters, and there are two functions we use:
Java code
Jstat-gcutil 'jvmPid'
Will show the situation of GC at the moment, in which YGC and FGC represent the number of small GC and large GC, YGCT and FGCT represent the time occupied by small GC and big GC, under normal circumstances, the number of large GC should be far less than small GC, for example, my current system small GC has 10w, while big GC has only 50 times, which is a good performance of program design and operation.
Java code
Jstat-gccapacity 'jvmPid'
It will show the usage of each memory pool in GC at the moment, which is similar to the result structure of the previous command. At the same time, there is also a problem. The data displayed is not very intuitive, and it would be much better to watch it through GUI.
JVM comes with the function of monitoring the status of GUI. In JDK5, we need to do some configuration to turn it on manually. First, we need to add some properties to the JVM startup item. Assuming that our system is a project running under the tomcat container, we can modify the JAVA_OPTS variable to open the monitoring service.
Java code
JAVA_OPTS= "$JAVA_OPTS-Dcom.sun.management.jmxremote-Dcom.sun.management.jmxremote.port=12345-Dcom.sun.management.jmxremote.ssl=false"
This will enable the service feature based on remote jmx monitoring. This configuration method also enables the default authentication mechanism. We also need to set permissions, user names and passwords in other places before we can log in. Let's put aside the rest of the work of these servers and talk about the client first.
We need GUI client access tool to view the information of the virtual machine remotely. JDK5 comes with a client named jconsole, which can be found in the bin folder of the JDK directory and can be run directly by double-click, click the "remote" tab, and then enter the remote IP, port, user name and password, if the server configuration is normal, you can successfully access.
Back on the server side, we also need to configure the remote user name and password for JVM, which modifies the $JAVA_HOME/jre/lib/management/jmxremote.access and jmxremote.password.template files.
First of all, modify the jmxremote.access file directly, uncomment the two user names and change it to
Java code
MonitorRole readonly controlRole readwrite\ create javax.management.monitor.*,javax.management.timer.*\ unregister
The difference between the two users is obvious, and you can cancel one.
Then change the file name of jmxremote.password.template to jmxremote.password, then edit the same two lines of users and change the password to what you want. It's very simple.
After that, you need to change the permissions of the jmxremote.password file to be readable and writable.
Java code
Chmod 600 $JAVA_HOME/jre/lib/management/jmxremote.password
At this point, it should be noted that 127.0.0.1 in the / etc/hosts file should be modified to your real public network IP, such as 210.209.83.37, and the IP returned by running the hostname-I command should also be 210.209.83.37. Every time you modify the above file, you have to restart JVM before the monitoring service will take effect.
After opening JVM, we can run the jconsole client, enter the IP port, user name and password, user name monitorRole or controlRole or your custom (different permissions).
You can also eliminate the user authentication section, just add-Dcom.sun.management.jmxremote.authenticate=false, or modify the location of the com.sun.management.jmxremote.password.file and com.sun.management.jmxremote.access.file custom permissions and password files, but this is not necessary.
After successful login, because of the GUI interface, all the information can be intuitively studied and accepted by us, but we still need to have some knowledge of JVM, especially GC. If we have the opportunity, we will continue to explain it in future documents.
The above is all the contents of the article "sample Analysis of Java performance Monitoring". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.