Dry Foods | Cloud Smart Perspective Treasure Java Code Performance monitoring implementation principle

Source: Internet
Author: User

This article illustrated, high-end atmosphere on the grade, thoughtful thinking of the article, a look and my usual style is different. That's right. This is not my writing, is my home tall and handsome, write a good code, fry a good dish of the male God architect Husband's masterpiece, has been published in the technical public number, after I authorized reprint, if there are technical problems, I ask him to answer ~ ~

First, the Java platform system and application scenarios

Since 1995, Sun Microsystems officially launched Java, and by 2006 Sun has opened its open source, with 20 years of history. Java itself is not just an object-oriented programming language, but a series of computer software and specifications formed by the technical system, this technology system provides a complete cross-platform development and deployment support, to achieve "write once, run everywhere" purpose. Java has been widely used in embedded, mobile terminals, enterprise servers, mainframe and other occasions.

Sun's official definition of the Java technology system consists of the following components:

* Java programming language

* Java virtual machines on various hardware platforms

* Class file format

* Third-party Java class libraries from business and open source communities

Figure: Java Technology Architecture Component diagram

Java Virtual Machine (JVM) is the foundation of the Java System and is responsible for interpreting and compiling bytecode in the form of. class files, while also responsible for memory management, hotspot code detection, and run-time compilation optimizations. It was the foundation of the virtual machine that made Java "write once, run everywhere." Java 20 years of development, in fact, is a virtual machine development process. Through the virtual machines developed by Sun and Bea, 2009 years later, Oracle has acquired these two companies and combined them with each other. Currently, it is open source virtual machine openjdk, which can be used by enthusiasts for research.

The JRE section is a standard environment that supports the operation of Java programs. The JDK is a superset of the JRE, including all of the JRE, plus tools such as compilers, debuggers, and so on.

Second, Java Performance monitoring requirements

For an enterprise application system, in most cases, it is certainly the integration of various systems developed by a variety of programming languages. We are very concerned about the availability of the system, the timely response, the consumption of resources, such as CPU, memory, various I/O, network bandwidth and other consumption situation. For the performance bottleneck of these problems, we can generally be summed up as external services (such as third-party APIs), resource reading and writing, code exceptions. If these problems occur in a timely and complete snapshot of the record, then we will provide sufficient evidence to solve the problem, it will be very easy to solve the problem.

For Java applications, the JVM itself provides the appropriate performance monitoring and tools, often after a problem, such as a memory leak or overflow, we will export the heap dump snapshot through the Jmap command, using the appropriate command jhat or other appropriate third-party memory analysis tools to analyze the object occupancy.

When the response is slow, we may use the Jstat Monitor command, or the JDK visualizer jconsole, VISUALVM to analyze the JVM's garbage collection type, and reclaim the frequency to speculate on whether it is a garbage collection. It is possible that we will continue to analyze the thread dump snapshot and take a snapshot of the thread's stack through Jstack to analyze whether there is a true deadlock, the corresponding slowness caused by the dead loop, and the high resource load situation.

When problems arise, many developers may be blindly using these tools to pinpoint problems, and in most cases this temptation will be reactive. Because these analysis tools mainly focus on Java-side analysis, such as the system calls the third-party API, if the third-party API has problems, it is not monitored. There are also access to files and DB resources that cannot be monitored.

Moreover, only advanced developers who are familiar with the Java Virtual Machine mechanism are better able to use and understand these tools, and for most ordinary Java developers, these problems will only make them helpless.

Bottlenecks such as external services such as third-party APIs, resource reads and writes, and code exceptions require code-level monitoring to find the crux of the problem directly, quickly, and efficiently. Calls to third-party APIs are time consuming, resource access time-consuming, code-throwing non-predictable exceptions, these common code monitoring can be fully monitored, and can capture records in real time, once a problem can quickly restore the scene of the incident. After discovering problems through code-level monitoring, you can also use the virtual machine built-in monitoring tools for further positioning.

Three, perspective Bao Java Monitoring Implementation principle


Figure: Java's execution model

In Java's execution system, a. Class bytecode file compiled by a. Java source file can be understood as an intermediate language.


Figure: Perspective Treasure Java Monitoring Implementation principle


Figure: Perspective Treasure Java Monitor Instance running diagram

1. What happens when the byte code is load to the JVM

* Once the callback function has been registered, any class file will be loaded by the ClassLoader before

Executes the callback function transform, which implements the class change operation within this method.

* Implementation of the Transform method, we are using ASM bytecode manipulation framework, ASM from the binary

Read, parse, and modify the behavior of the class in the form of a class file.

* The basic code form of the transform method is as follows:

2. How to actually change the class behavior

* On the basis of ASM, we abstract this business model

* Common intercept Probes

* Common Runtime interception processor

* Supported interception definition filter rules

* Behavior that corresponds to the business model

When defining an interception description, specify which classes and methods are blocked by the filter, and then, at the point of these behaviors, you can bury the probe, the processor. Override Visitcode, VISITINSN, visitmaxs respectively to implement method entry, return, exception related operation rewrite.

Iv. Perspective Bao Java Monitoring deployment process

1, Login Cloud Wisdom Perspective Bao official website, click on the top right of the page navigation "free trial", correctly fill out the free trial application information will pop up the following dialog box, while the activation of the mail will be automatically sent to your mailbox, follow the process to register an account.

2. After successful registration, login to the perspective treasure, click Configure-Application, download and install the smart Agent in the configuration page. After the installation is successful, the Smart agent automatically obtains the host information based on the system configuration, and after approximately two minutes, you can view the server's CPU, memory, network card, disk, and process performance data in the "host → server" module.

3, if you want to monitor the application run time code, host services and database performance data, you need to further install and configure the various plug-ins provided by the Smart agent, because the smart agent implements an open plug-in structure, for each running time code, The monitoring of the service and the database is implemented by the corresponding plug-in.

After the installation is complete, the Smart agent automatically discovers your application components during the loading process, and you can add the Java agent manually if you do not automatically monitor the Java environment. As shown, click "Manage" portal, go to "plugin management", click "Add Service" at the bottom of the page, select Javaagent, then click "Create".

When you are finished, click "on". (The on operation simply initializes the user's information so that the information collected later can be correctly passed back to the user.) )

After the above is done, in {smartagent installation path}/plugins, you will see the following form of

Under {Smartagent's Installation path}/plugins/javaagent_1442476463x1002x0/conf folder, look at the app.conf file to see if the Hostkey value within the file is an encrypted form similar to the following

The above situation indicates that Javaagent has downloaded the startup initialization successfully.

4, install javaagent to various application server, such as Tomcat\jboss\weblogic. (This operation refer to the official website https://www.toushibao.com/can)

5, just start the appropriate server, and then access your app URL, the URL to use the code execution can be presented to you, once the slow problem is also at a glance. As motioned

Five, Perspective Bao Java Code performance monitoring features

In terms of functionality, perspective treasure, whether in Java or other mainstream languages such as. NET, PHP, includes: View the 10 most slowly executed elements, including the number of elements executed, duration, and percentage of elapsed time; View HTTP request parameters, including the requested response status, Link page, Specific request parameters and return results; View detailed tree-like information for the code execution stack, including the calculation time of each method, total time spent and number of calls, the slowest way to see the special identity directly, and view the total time-consuming ordering of SQL statements, including the total time spent on SQL execution, the number of executions, and the specific query statements ; third-party API calls.


End-to-end performance monitoring

In terms of performance, how much is the impact of the Javaagent code monitoring probe package from cloud wisdom perspective on the user's performance? From the installation package itself, it is very small, only 1.5M. Run the application separately without installing the Java Probe Package and installing the Java probe package. The difference in CPU usage, memory consumption, and TPS is within 5% of the test comparison.

Dry Foods | Cloud Smart Perspective Treasure Java Code Performance monitoring implementation principle

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.