Java comes with performance monitoring tools: Monitoring and Management Console jconsole use

1. Introduction
want to validate some of the tuning parameters jvm with you (such as Xms, Xmx, etc.) there is no work?
The number of threads in the actual operation of real-time monitoring want your custom thread pool, there is no deadlock?
Applications appear java.lang.OutOfMemoryError: Java heap space, you need to know to adjust Xms, Xmx. Want real-time monitor heap memory usage of your Java applications, and best for you Xms, Xmx and other parameters such as peak data set?
Applications appear java.lang.OutOfMemoryError: PermGen space, you need to know to adjust XX: PermSize, XX: MaxPermSize. Want to find your peak usage applications PermGen permanent area, and according to its setting reasonable XX: MaxPermSize parameters such as: PermSize, XX?
As we all know, JVM heap memory is divided into the young generation and the old generation. JVM default ratio of the old generation and the young generation under (ie XX: NewRatio, the name likely to create confusion, that is considered to be younger generations than older generations) to 2 (ie the JVM heap memory is divided into three average, in the boss takes up two, and the young generation take up a copy. references Sun Java System application Server Enterprise Edition 8.2 Performance Tuning Guide), this ratio is not suitable for all situations, especially when your application in a local variable is far greater than the global variable, and a large number of local variable life cycle is very short time. How rational allocation of the young generation (Young Generation, namely Eden and two Survivor areas of the district and) depending on the application and operation of real-time operation of the old generation (Old Generation, ie Tenured area) ratio XX: NewRatio value?
Java comes with performance monitoring tools: Monitoring and Management Console jconsole, it can provide a Java process memory, threads, class loading, jvm summary and MBean and other real-time information, may be able to provide a reference to the above question.

 

2. JVM parameters
before starting jconsole let's take a look at some of the main parameters of JVM:
-Xms initial / minimum heap size
-Xmx maximum heap size
-Xmn the young generation size
-XX: NewSize the young generation size
-XX: MaxNewSize the young generation maximum
-XX: NewRatio old generation and the young generation ratio
-XX: MaxPermSize maximum permanent generation
-XX: PermSize permanent generation initial value of
some information that, Xms, Xmx set the JVM memory size is wrong, JVM in addition to the heap memory reserved for use by developers as well as non-heap memory.
Readers may find that there are three ways to divide the young generation size: -Xmn way, -XX: NewSize + -XX: MaxNewSize way, -XX: NewRatio way. Are three kinds, highest to lowest priority order is -XX: NewSize + -XX: MaxNewSize embodiment, -Xmn mode, -XX: NewRatio manner, that is arranged behind the lower front of the high priority of the it was overwritten.

 

3. The machine enabled Java jconsole to monitor the process
CMD switch to% JAVA_HOME% / bin directory, direct execution jconsole


To open the Java Monitoring and Management Console:

 

 

 Local list shows all the processes in the local implementation of Java process, double-click the process that you are interested in (such as the PID is 8504), the process can be monitored:

 

 

 

 

 

4. Remote Monitoring Java process

For remote monitoring of Java process, when you start it you need to enable JMX.
To tomcat on the remote host, for example, to find an available remote port jmx, such as 9999:

 

 

 No news is good news ~ front% 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"

Figure

Write (execution% tomcat% / bin / shutdown.sh) will be reported using the port has been closed when an exception in tomcat:

Error: Proxy throw exceptions: java.rmi.server.ExportException: Port already in use: 9999; nested Exception IS: 
        java.net.BindException: Address already in use

This is because the tomcat configuration will be executed JAVA_OPTS in the start and stop time. This can only use kill -9 to shut down a tomcat ...

The solution is configured to monitor write CATALINA_OPTS in:

JAVA_OPTS="-Xms1024m -Xmx2048m -XX:MaxPermSize=128m"
CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

On it. CATALINA_OPTS configuration is only executed when tomcat starts. References: https: //bowerstudios.com/node/636.


Then restart tomcat, open Java monitoring and management console in the machine, "remote process" jmx enter the remote host name and port number:

 

 Click on "Connect" button on the remote host tomcat on a real-time monitoring:

 

 

Some useful information provided 5. jconsole

Next Step 4 cases look down.

5.1. JVM configuration information to check whether the work

Click "VM Summary" to view the JAVA_OPTS we have just set some parameters have been worked:

 

 

5.2. Tomcat thread pool, a custom thread pool number of real-time monitoring

Tomcat is still the mystery of the thread pool and a headache? Also define your own thread pool for the "black box" general distress? Take a look at the following figure:

 

 Our tomcat has just started, can be seen only from a http-8080-Acceptor-0 thread, we went to visit about our project, and then come back to see:

 

 http-8080 thread suddenly increased to eight. Not everything is clear, among under control?

5.3 Memory Usage actual consumption

Click Java monitoring and management console "Memory" leaf item, you can see tomcat heap memory usage:

 

 Chart, there are many options:

 

 We look at the Eden area:

 

 

 

 Eden area of ​​basic and almost the entire heap memory of the trend. Look at Survivor areas:

 

 

 

 Survivor areas in a relatively short period of relatively stable trend. Look Old Gen District:

 

 

This trend is more stable, and contrast Survivor District, Old Gen zone two pictures, you can clearly see, at approximately 19:58 that time there will be a number of objects moved from the Old Gen Survivor District area. Finally, look at Perm Gen zone.
This trend is the most stable. It is clear that, at about 19:58, when we visit about our projects, some of the new class and other static resources loaded into the JVM. Figure 5.4 Number of loaded class also confirmed this.

5.4 The situation tomcat load classes

 

 

6 with the use of jmap

 

 Tomcat we first find the PID of the process is 13863, and then perform jmap -heap 13863:

 

 Heap Configuration in the column we just basically with those, such as MaxHeapSize is 2048 MB, MaxPermSize is 128 MB. And this is the same as in 5.1.

 

Guess you like

Origin www.cnblogs.com/yuming1983/p/11569784.html