`

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

 
阅读更多

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

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

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

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

Jrockit 有两个组件:

1. 虚拟机 JVM Jrockit Real Time , 与 SUN JDK/JVM 是完全兼容的。

2. 监控软件 Client Jrockit 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 解压许可证

winrar gunzip 解压。

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 Time JDK

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 服务器,则 Tomcat JRockit 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 堆栈分配跟踪

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics