When we do Java development, we need to stress test the program before going online, to fully monitor the performance of the program, to understand the CPU, memory, gc,classes, thread, etc. of the JVM, or to run the program in order to diagnose problems or optimize the process. There are more tools on the market for Java profiling, such as commercial jprofiler,jclarity and so on, there are free JDK's own tools, such as VISUALVM,JCONSOLE,JMC and so on, So how do we use these tools for performance monitoring and tuning when we deploy Java applications to Azure Cloud service? This article takes the example of VISUALVM and JMC from Oracle JDK 1.8.
Let's take a look at the effect of VISUALVM running locally, my test environment launches applications such as ECLIPSE,TOMCAT, enter your Java installation directory, open the Bin folder, find the JVISUALVM program, and open the main interface to see, A locally run Java program has been discovered:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/08/wKiom1YOqLuiTfBpAAJGE9SgyQI964.jpg "title=" MainPage. PNG "alt=" Wkiom1yoqluitfbpaajge9sgyqi964.jpg "/>
You can see the 3 Java programs running locally, double-click the PID 19256 Tomcat program, you can see a wealth of options, such as Overview,monitor,thread:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/08/wKiom1YOqeHDq2HvAAQmco8Jg7Y442.jpg "title=" Overview. PNG "alt=" Wkiom1yoqehdq2hvaaqmco8jg7y442.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/06/wKioL1YOqjnxKOQOAAfnd6H4Ywg632.jpg "style=" float: none; "Title=" Monitor. PNG "alt=" Wkiol1yoqjnxkoqoaafnd6h4ywg632.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/08/wKiom1YOqi_gSN0nAAeHIsnkljQ683.jpg "style=" float: none; "title=" Thread. PNG "alt=" Wkiom1yoqi_gsn0naaehisnkljq683.jpg "/>
So the question is, how do we monitor the performance of the JVM after we deploy Java Web App to Azure Cloud service? An easy way is to use the cloud service's RDP service, log on to the remote machine, and then open the local VISUALVM for monitoring, but we will find that although our Java application can be accessed normally, However, it is not possible to see Tomcat or Jetty Application server processes, nor can they monitor:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/08/wKioL1YP8Xmg8DCYAAKmwwALzj4987.jpg "title=" Nothreadvm.png "alt=" Wkiol1yp8xmg8dcyaakmwwalzj4987.jpg "/>
In my test, I found that the most important reason is that when the cloud service starts jetty, Java is run as a daemon, so it cannot be detected in the local instance of cloud service with VISUALVM. VISUALVM get JVM data in two ways, JMX or Jstat, after the Java app is deployed in the cloud service, you need to explicitly specify the JMX parameters to open the service before you can monitor, the following steps are step by step:
This article assumes that you have mastered the quantity:
A. Deploy Java apps to Azure cloud services (http://cloudapps.blog.51cto.com/3136598/1699880)
B. Configure Cloud service remote connections
Open your Azure deployment project in Eclipse and find package.xml:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/0F/wKiom1YRCySBlMpVAALYBTios94243.jpg "title=" Package. PNG "alt=" Wkiom1yrcysblmpvaalybtios94243.jpg "/>
Locate the Jetty startup line and add the JMX parameter after Java start:
-dcom.sun.management.jmxremote=true-dcom.sun.management.jmxremote.port=1099 (this port can be defined by itself)
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=false
Locate the jetty startup line:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/0C/wKioL1YRDHbQgHHQAAFnM5PPpLA166.jpg "style=" float: none; "title=" Compojava.png "alt=" Wkiol1yrdhbqghhqaafnm5pppla166.jpg "/>
Add the JMX parameter above to the jetty startup parameter
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/0F/wKiom1YRDGXRDhAuAAIXy8PK3VI745.jpg "style=" float: none; "title=" Compojavaadded.png "alt=" Wkiom1yrdgxrdhauaaixy8pk3vi745.jpg "/>
Save the changes and redeploy the project to the Azure cloud service:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/0F/wKiom1YRDVCDyV2fAAMe2-Ko_bY530.jpg "title=" Deploytocloud-1.png "alt=" Wkiom1yrdvcdyv2faame2-ko_by530.jpg "/>
With Remote Desktop Connection to the Azure cloud service instance, the application is typically deployed under "E:\approot", open the directory, go to the JDK's Bin directory, and open VISUALVM:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/0C/wKioL1YRD-CQKZQdAASNDjfvuFg914.jpg "title=" Remotedesktop.png "alt=" Wkiol1yrd-cqkzqdaasndjfvufg914.jpg "/>
You can see that there is currently no information related to jetty, only VISUALVM a process, we previously deployed jetty has actually turned on JMX, can be a source of VISUALVM to provide related performance data, So let's do a simple configuration for VISUALVM, select "File"-"Add JMX Connection":
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/0C/wKioL1YREWjgNx5LAAMMQ01C32A381.jpg "title=" Addjmx.png "alt=" Wkiol1yrewjgnx5laammq01c32a381.jpg "/>
In connection enter 127.0.0.1:1099 (previously configured port number), in the Display name center of your favorite name, such as jetty, click OK to complete.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/0C/wKioL1YREKOx-ASeAAJyuazx_4I394.jpg "title=" Configjmx.png "alt=" Wkiol1yrekox-aseaajyuazx_4i394.jpg "/>
By double-clicking the jetty in the list on the left, you can see that you can already monitor your local Java application via JMX:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/0C/wKioL1YREhCTCuI6AAL41CzNFSM752.jpg "style=" float: none; "title=" Jetty.png "alt=" Wkiol1yrehctcui6aal41cznfsm752.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/0F/wKiom1YREgDw200zAAUcyhru5Tk273.jpg "style=" float: none; "title=" Jetty2.png "alt=" Wkiom1yregdw200zaaucyhru5tk273.jpg "/>
So far, VISUALVM is ready to work, so we bang, by the way, the Java Mission Control and Jconsole also configured:) also open E:\app\JDK_HOME\bin, double-click JMC, start Java Mission Control:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/0C/wKioL1YRE2rACTeyAASehFEFEm8328.jpg "title=" jmc- Start. PNG "alt=" wkiol1yre2racteyaasehfefem8328.jpg "/> Clicks" Click here to start using .... ", start using JMC
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/0F/wKiom1YREuyQ_NC2AAMV6VNAVIw267.jpg "title=" JMC. PNG "alt=" Wkiom1yreuyq_nc2aamv6vnaviw267.jpg "/>
In the same way, you can see that in the JMC, only the VISUALVM and JMC that have been started are visible, not jetty. Select File-connect to configure the JMX:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/74/0F/wKiom1YRIACg4qyFAAFs2f9eUhg472.jpg "title=" Jmcconnect.png "alt=" Wkiom1yriacg4qyfaafs2f9euhg472.jpg "/>
10. In the main interface that appears, select "Creat New Connection", go to the next page, configure the local port to 1099 in the main interface, click "Test Connection" to test, if everything is OK, then the test status is okay:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/74/0C/wKioL1YRFtTRIfBcAAFrC7SfY7c385.jpg "title=" Jmcnewconnection. PNG "style=" Float:none; "alt=" wkiol1yrfttrifbcaafrc7sfy7c385.jpg "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m00/74/0f/wkiom1yrfsktzlo5aajutjfveso519.jpg "style=" Float:none; "title=" Jmc-connectconfig.png "alt=" Wkiom1yrfsktzlo5aajutjfveso519.jpg "/>
11. Click Next, in the selection, select Start JMX Console and click Finish:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/0C/wKioL1YRF3nAJhFJAAFJoLDcArg834.jpg "title=" Jmc-startjconsole.png "alt=" Wkiol1yrf3najhfjaafjoldcarg834.jpg "/>
12. Then in the new interface you can use Jconsole to monitor your application and see the metrics:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/0C/wKioL1YRF8_SQg29AAbdk94QVgU337.jpg "title=" 1099_ Overview. PNG "style=" Float:none; "alt=" wkiol1yrf8_sqg29aabdk94qvgu337.jpg "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m00/74/0f/wkiom1yrf7yj61wiaau6_clpsn8380.jpg "style=" Float:none; "title=" 1099_MBean.PNG "alt= "Wkiom1yrf7yj61wiaau6_clpsn8380.jpg"/>
We've configured how to configure VISULVM and jmc/jconsole for performance monitoring of Java apps on Azure cloud services, and you can see that most of the tools that are available on Windows can run well on Azure cloud services, And we can monitor it conveniently through RDP.
This article is from the "cloud Big Data Life" blog, make sure to keep this source http://cloudapps.blog.51cto.com/3136598/1700264
Use VISUALVM to monitor Java applications in Azure cloud services