世界最快的Java虚拟机JVM与内存泄露诊断

来源:互联网 发布:取代迅雷的软件 编辑:程序博客网 时间:2024/04/29 07:36

1简介

Oracle JRockit JVM(即原先的 Bea JRockit JVM)系列产品是一个全面的Java运行时解决方案组合,是业内性能最高的 Java 虚拟机,超过Sun标准虚拟机,大量的行业基准测试显示,基本JRockit JVM是世界上最快的JVM

Oracle JRockit是为高性能服务器上运行大规模的关键任务型的服务器端应用而设计,包括支持64位的Intel至强和Intel安腾处理器,支持多种平台,包括SolarisLinux服务器及基于SPARC的系统,通过专为改进应用可靠性而设计的JRockit Mission Control套件提供了前所未有的控制能力。

Oracle JRockit面向延迟敏感型应用的解决方案JRockit Real Time提供以毫秒或微秒计的JVM响应时间,适合财务前端办公、军事指挥与控制和电信网络的需要。使用JRockit产品,客户已经体验到了显著的性能提高和硬件成本的减少(达50%)。

通过 JRockit Real Time 提供业内领先的实时基础架构功能,通过 JRockit Mission Control 提供无与伦比的 JVM 诊断,如:查看Java内存泄露等。

Jrockit有两个组件:

1. 虚拟机JVMJrockit Real Time,与SUNJDK/JVM是完全兼容的。

2. 监控软件ClientJrockit Mission Control

 

以前这套软件只提供1个小时的免费监控时间。就是说JVM启动1个小时内,监控软件(Client)可以连接上监控工作,这对一天内存泄漏很少的应用程序来说,没有什么意义。现在已经完全免费了,无需许可证文件。

Jrockit是一套可以在生产环境中进行内存监控的高效软件,其他软件都会严重降低虚拟机的效率。因为内存泄漏有时就算在压力测试中也很难发现。大部分都是在生产环境中产生的。如果没有一个基本不影响运行效率的软件,想解决只能靠运气。

2许可证

2.1新版本

c:/> java -version

对于 >= JRockit R27.6, 你无需许可证文件。

2.2老版本

然而, 若你使用 < R27.6的老版本, 需要下载安装一个老的许可证文件。

2.2.1下载许可证

下载老的许可证包:

http://download2.bea.com/pub/license/All%20Products/BEA_WebLogic.zip

2.2.2解压许可证

       winrargunzip解压。

2.2.3拷贝许可证

解压后将其中的LIC-WLRT20.txt文件改名为license.bea拷贝到%JROCKIT_HOME%/jre/下。

3软件安装

1. 下载地址:http://www.oracle.com/technology/software/products/jrockit/index.html

下载Jrockit Mission Control(监控软件Client)和Jrockit Real TimeJDK

2. 二进制文件安装。

4 Web服务器配置

       我们的应用运行于某Web服务器,假如Java类运行于Tomcat容器。配置如下。

4.1修改JAVA_HOME

修改系统环境变量: JAVA_HOME=<Jrockit安装路径>

如:JAVA_HOME=E:/Program_Files/Java/jrrt-3

4.2激活Jrockit管理台

<apache-tomcat>/bin/catalina.sh修改:

JAVA_OPTS=" -verbosegc -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=<Client IP> "

 

也可:

java -Xmanagement:ssl=false,authenticate=false,autodiscovery=true

 

运行Tomcat服务器,则TomcatJRockit JVM上运行,而非标准Sun JVM

Tomcat控制台提示:

[JRockit] Management server started on port 7091, ssl=false, authenticate=false.

[JRockit] JDP server up. Broadcasting target 100.199.10.27:7091 every 5000 ms.

5监控端

服务器可在异地,例如:益体网服务器在电信中心机房,本地监控端远程连接它。

5.1运行jrmc

首先安装Jrockit Mission Control,然后运行之:

<Jrockit安装路径>/bin/jrmc.exe

Oracle BEA也提供了Eclipse插件:

http://www.oracle.com/technology/software/products/jrockit/missioncontrol/updates/eclipse-3.3/jrmc/,当遇到问题可以直接定位到Java代码。

5.2新建连接

JVM浏览器视图中,对连接器文件夹右键,选择新建连接。

 

弹出下图:

在“主机”处输入IP,服务器开放的端口已经是7091,所以不必修改。

点击“测试连接”状态如果是确定则代表已经连接。

 

点击Finish保存新建的连接。在“连接器”文件夹新建了一个连接。

5.3客户端无法连接JVM

5.3.1未启动管理服务器

1. (JDK 1.4) You must do so if you want to enable your application for remote monitoring or if you want to monitor an instance of a JRockit JVM running with JDK 1.4. You can start the management server by adding the -Xmanagement option to your Java command line.

2. SSL and authentication are available in JDK 1.5/1.6 and will be enabled by default. If you do not want to set up certificates, SSL and authentication can be disabled by providing ssl=false and authenticate=false. Also, if you want to use the remote discovery feature of JRockit, you can enable it by setting autodiscovery=true; :

java -Xmanagement:ssl=false,authenticate=false,autodiscovery=true

 

3. You can also start the management server on an already running JRockit JVM by using the jrcmd utility available in the JROCKIT_HOME/bin directory.

5.3.2协议正确性

Are you using the correct protocol?

- The easiest way is to ensure that you are using the same version of the JRockit JVM you want to monitor as the JRockit JVM running the JRockit Mission Control Client. If that is not an option, you can use the radio buttons in the connection dialog box in JRockit Mission Control to select the correct protocol for the JDK version of the JVM you want to connect to: 1.4 will select RMP and 1.5 and later will select JMXRMI.

 

For earlier versions of the JRockit Mission Control Client, these radio buttons don?t exist. In these versions, to make a 1.5 JRockit JVM instance connect to a 1.4 version, you must explicitly specify the JMX Service URL. The format of the service URL is:

service:jmx:rmp://<hostname>:<port>

: service:jmx:rmp://localhost:7091

5.4.3端口开放

Are the correct ports opened?

- Note that JMX over RMI uses two ports and that one of the ports will not be known beforehand. Please see JRockit Mission Control Communications for details.

Is the communication caught in a firewall?

Please see JRockit Mission Control Communications for more information.

 

When attempting to connect the JRockit Mission Control Client to a JVM, I get a stack trace indicating that JRockit Mission Control attempts to communicate with a strange IP or host name. What does this mean?

Sometimes RMI can have a problem determining which address to use. This can happen because of

 

Access restrictions in the Security manager,

The machine being multihomed and RMI picking the wrong interface

A misconfigured hosts file or a number of different network related configuration problems.

If all else fails you can try specifying the java.rmi.server.hostname system property. Please note that this can affect applications running in the JRockit JVM.

5.4监控内存

1. 在新建的连接器上点击右键,选择“启动Memleak”,弹出内存泄露检测器:

 

“趋势”选项卡,里边标注了占用JAVA堆大于0.1%的类和数组。

“类型”选项卡,显示了类型与类型之间的引用情况。

“实例”选项卡,显示了实例之间的引用情况。

“分配堆栈跟踪”选项卡,显示了指定类型在虚拟机运行过程中被使用的情况。

 

2. 在新建的连接器上点击右键,选择“启动控制台”,弹出控制台:

 

5.5实战

5.5.1 T1-T2时间

在一段时间间隔T1-T2内,查看内存使用情况(趋势选项卡):某类增长(字节/秒)和大小(KB)持续增长,没有释放内存,似乎GC没有起作用,则可怀疑该类内存泄露。

5.5.2堆栈分配跟踪

知道是哪个类出了问题,然后就需要知道系统中有哪些类使用了它。右键,选择“显示分配跟踪”,进入“分配堆栈跟踪”选项卡,跟踪定位。