Using visual VMs to view the Tomcat runtime JVM memory in Linux

Source: Internet
Author: User
Tags garbage collection server memory visualvm

in the production environment, the server memory overflow, suspended animation or thread deadlock, etc., cause the service to be unavailable. The workaround that we often use is to analyze the error diary and then find out where the code is going to go wrong, which might work, but it takes a lot of time to troubleshoot, or the code itself is not wrong, but it consumes too much memory when the traffic is large. Garbage objects are not in time to recover and so on other circumstances, so it is extremely difficult to troubleshoot, then there are some visual tools to help us to view the current application services in detail the memory situation, so that we can solve the anomaly, optimize the code, optimize service and so on to provide some suggestions? Fortunately, the JDK provides us with one such visualization tool for free, VisualVM, of course, there are some commercial or free other similar tools in the market, such as Jprofiler, Jconsole and so on. I'll show you how to use visual VMs to connect to a Web app deployed on Tomcat on a Linux environment in a window environment.

1. Environmental Preparation and Description
Win7
Jdk1.6.0_31
Tomcat6
Linux CentOS
Local VISUALVM to connect to the remote JVM, the configuration needs to be made, and VISUALVM is mainly remotely connected through JMX and jstatd two ways.
JMX connections can look at System information, CPU usage, how many timelines the thread is on, manually perform garbage collection, and more at the system-level level.
The jstatd connection method provides JVM memory distribution details, garbage collection maps, thread details, and even the size of an object's memory usage.
Therefore, to view the specific information of the remote JVM, it is best to configure the connection in both ways.

2, the configuration of JMX connection

Add the following configuration at the end of Tomcat's bin/startup.sh so that the Web app under Tomcat can be connected via VISUALVM JMX

export CATALINA_OPTS="$CATALINA_OPTS-Dcom.sun.management.jmxremote=true-Djava.rmi.server.hostname=19.129.251.16 -Dcom.sun.management.jmxremote.port=8099-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=false"

Address of the Linux server where the Hostname:tomcat resides
Port: Exposed access port, cannot be duplicated with other ports
Added after:

After configuration, start Tomcat to see if you can access the address configured above 10.5.227.81:8999

Use Telnet to succeed, stating that the address is accessible and if not, you need to troubleshoot the network environment
A, the remote Linux server address 10.5.227.81 and your machine connectivity, using the ping command to see through
B. See if the firewall restricts access to the port

If there is no problem with the above steps, then you are nearing success more than half
Next, open Jdk/bin/jvisualvm.exe on the local machine, which is the start page of the visual VM

Create a new remote connection, "remote" right-–> "Add remote Host", enter the server address of the above configuration, djava.rmi.server.hostname=10.5.227.81

Select the added host, right-–> "add jmx Connection", enter the port configured above 8999,-dcom.sun.management.jmxremote.port=8999

After the JMX connection is successful, you can see the parameters of the JVM, such as JVM-related parameters such as stack size, view server CPU consumption, manually perform garbage collection, export the heap dump image, view the classes, the total number of threads, and the distribution of permissions

3. Configuration of JSTATD Connection
If you want to look at the usage of each partition of the JVM's memory, which threads, variables use memory details, you also need to establish a JSTATD connection. Create a new file Jstatd.java.policy under Tomcat (or under a path that specifies the absolute path below), which is primarily used to grant VISUALVM remote connection with the following content

   grant codebase "file:${java.home}/../lib/tools.jar" {     permission java.security.AllPermission;   };

After creating the Jstatd.java.policy, the following:

Execute the following command in the Linux service window

[root@qgserver ~]# jstatd -J-Djava.rmi.server.hostname=10.5.227.81  -J-Djava.security.policy=/data/tomcat6-fssmyx/jstatd.java.policy 

10.5.227.81 is the IP address of the Linux server, same as above.
Jstatd.java.policy is the file created above, note to specify the absolute path, my is placed in/data/tomcat6-fssmyx/, according to the actual situation configuration.

After successful execution, the JSTATD connection is automatically established in the Visual VM, you can see all tomcat on this machine, find the Tomcat Web service that you need to view

Open the Visual GC tab to see Tomcat's memory usage map, permanent zone, old age, new generation usage, garbage collection information. To view the JVM with more tools, you can install more tools by using ' Tools ', ' plugins '

To this, using the local VISUALVM to view the remote JVM has finished, thank you for viewing!!

Using visual VMs to view the Tomcat runtime JVM memory in Linux

Related Article

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.