Java应用程序CPU /负载较高时,对JDK8建 [英] Java application CPU/load much higher when built against JDK8

查看:184
本文介绍了Java应用程序CPU /负载较高时,对JDK8建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Amazon EC2上(c3.large,亚马逊的Linux)在Eclipse月神在Windows开发的Java应用程序。这个应用程序在一个非常一致的传入速率工作。当我建立对JDK 8u31的应用,EC2 CPU的负荷比对构建JDK 7u75同一个应用程序要高得多。

应用程序最初运行与EC2默认的JRE,我加入了OpenJDK的1.8.0.31采取了Java 8进程WAITFOR(长超时,为TimeUnit单位)的优势。主要工作这个应用程序包括调用使用的Runtime.exec的应用程序。

  $ sudo的替代品--config java的

有2个方案,提供Java的。

  选择指令
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
 + 2 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-2.b13.5.amzn1.x86_64/jre/bin/java
 

例平均负载,当应用程序构建针对1.7:

 顶 -  0时二十分28秒了4天,10:41,4个用户,平均负载:0.37,0.26,0.52
 

例平均负载,当应用程序构建针对1.8:

 顶 - 二十三时45分52秒了4天,10点06,4个用户,平均负载:2.28,2.60,2.01
 

看起来这可能与开放JDK 1.8.0.31,但我不知道如何调试这一点。有没有code的变化,我只是改变了合规水平和建设之间的1.7和1.8在Eclipse中月神。任何想法,为什么负载会有那么多不同?

更新:

我看到类似的高CPU负载,当我使用Oracle JDK在EC2上。

  $ sudo的替代品--config java的

有3个方案,提供Java的。

  选择指令
-----------------------------------------------
   1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-2.b13.5.amzn1.x86_64/jre/bin/java
* +3 /usr/java/jdk1.8.0_31/bin/java
 

平均负载:

 顶 -  1点45分27秒了4天,12时06分,4个用户,平均负载:2.28,1.50,1.04
 

解决方案

您所描述的症状,但我不认为这是不够下去,如果仅仅是因为这将是不可能的搜索之类的java 8个高CPU的任何地方(谷歌,java的错误巡游等),并找到有用的结果。不幸的是,你需要收集什么使用的CPU的详细信息。下面是关于如何做到这一点的一些想法:

  1. 资料有诸如VisualVM的一个工具。负载差异是极端的,所以你可能只能够是怎么使用的CPU被发现。
  2. 找到繁忙的线程。你可以拿一把线程快照和眼球,或者尝试一个工具,这样的 jvmtop
  3. 检查一下垃圾收集器在做,无论是通过启用GC日志记录或如jstat工具。
  4. 使用<一个href="http://stackoverflow.com/questions/10384850/seeing-all-the-system-calls-that-were-made-by-a-java-program">strace追踪系统调用执行。

I have a Java application developed in Eclipse Luna in Windows that runs in Amazon EC2 (c3.large, Amazon Linux). This application processes work at a very consistent incoming rate. When I build the application against JDK 8u31, the EC2 CPU load is much higher than the same application built against JDK 7u75.

The application originally ran with the default JRE on EC2, and I added the OpenJDK 1.8.0.31 to take advantage of the Java 8 Process waitFor(long timeout, TimeUnit unit). The main work this application does involves invoking an application using Runtime.exec.

$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
 + 2           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-2.b13.5.amzn1.x86_64/jre/bin/java

Example load average when the application is built against 1.7:

top - 00:20:28 up 4 days, 10:41,  4 users,  load average: 0.37, 0.26, 0.52

Example load average when the application is built against 1.8:

top - 23:45:52 up 4 days, 10:06,  4 users,  load average: 2.28, 2.60, 2.01

It seems like it may be related to the Open JDK 1.8.0.31, but I don't know how to debug this. There are no code changes, I'm only changing the compliance level and build between 1.7 and 1.8 in Eclipse Luna. Any idea why the load would be so much different?

UPDATE:

I see similar high CPU load when I use the Oracle JDK on EC2.

$ sudo alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-2.b13.5.amzn1.x86_64/jre/bin/java
*+ 3           /usr/java/jdk1.8.0_31/bin/java

Load average:

top - 01:45:27 up 4 days, 12:06,  4 users,  load average: 2.28, 1.50, 1.04

解决方案

You've described symptoms, but I don't think this is enough to go on, if only because it will be impossible to search for things like "java 8 high CPU" anywhere (google, the java bug parade, etc.) and find useful results. Unfortunately, you need to collect more information about what's using CPU. Here are some thoughts on how to do so:

  1. Profile with a tool such as VisualVM. The load differences are extreme, so you might just be able to spot what's using the CPU.
  2. Find the busy threads. You can take a bunch of thread snapshots and eyeball it, or try a tool such a jvmtop.
  3. Check what the garbage collector is doing, either by enabling GC logging or with a tool such as jstat.
  4. Use strace to trace the execution of system calls.

这篇关于Java应用程序CPU /负载较高时,对JDK8建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆