Viewing the Tomcat runtime JVM memory __linux in Linux using Visual VMS

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

in the production environment, the server memory overflow, suspended animation or thread deadlock are frequently occurred, which leads to service unavailable. The solution we often use is to parse the bug diary and find out where the code is going wrong, and that might work, but it takes a lot of time to sort it out, or the code itself is not wrong, but the traffic consumes too much memory, Garbage objects are not timely recovery, and so on other circumstances, so that the exception is difficult to troubleshoot, then there are some visual tools to help us to view the current application of the memory of the service, so that we solve the exception, optimize the code, optimize the service and other aspects to provide some suggestions. Fortunately, the JDK provides us with one of these visual tools for free, VISUALVM, and of course there are commercial or free other similar tools on the market, such as Jprofiler, Jconsole, etc. I'll explain how to use a visual VM to connect to a Web application 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 a remote JVM, which requires a related configuration, VISUALVM is connected remotely via JMX and JSTATD in two different ways.
A JMX connection can look at System information, CPU usage, how many times the thread is threaded, manually perform garbage collection, and more at the system level.
The jstatd connection can provide JVM memory distribution details, garbage collection maps, thread details, and even the size of an object using memory.
Therefore, to view the specific information of a remote JVM, it is best to configure the connection in both ways.

2, the configuration of the JMX connection

Add the following configuration at the end of Tomcat's bin/startup.sh so that Web applications under Tomcat can be connected through 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 "

The address of the Linux server where Hostname:tomcat resides
Port: Exposed access port, cannot repeat with other ports
Added effect chart:

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

Success with Telnet means that the address is accessible, and if not, you need to troubleshoot the network environment
A, remote Linux server address 10.5.227.81 and your machine's connectivity, using the ping command to see the impassability
b, see if the firewall has restricted access to the port

If the above steps are not problematic, then you are close to success half
Next, open Jdk/bin/jvisualvm.exe on the local machine, as shown in the Start page of the visual VM

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

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

After a successful JMX connection, you can view JVM parameters such as stack size, view server CPU consumption, perform garbage collection manually, export heap dump mirrors, view the total number and distribution of classes, threads, and so on.

3, the JSTATD connection configuration
If you want to see how the JVM's memory partitions are used, which threads, variables use the details of the memory, you also need to establish a JSTATD connection. Create a new file Jstatd.java.policy under Tomcat (or a path where you specify an absolute path when you use it), which is primarily used to grant VISUALVM remote connections with the following contents

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

After creating the Jstatd.java.policy, the following effect is shown:

Execute the following command in the Linux Services window

[Root@qgserver ~]# jstatd-j-djava.rmi.server.hostname=10.5.227.81  

10.5.227.81 is the IP address of the Linux server, the same as above.
Jstatd.java.policy is the file established 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 that is automatically established in the Visual VM allows you to see all Tomcat on this machine and find the Tomcat Web service that you want to view

Open the Visual GC tab to see Tomcat's memory usage map, permanent area, old age, new generation usage, and garbage collection information. To see the JVM with more tools, you can install more tools through the ' Tools '-> ' plugin '

To this end, use the local VISUALVM to view the remote JVM is finished, thank you for your view.

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.