java方法的执行时间长 [英] High Execution time on java methods

查看:171
本文介绍了java方法的执行时间长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CentOS 5.4 VPS 上运行 Java 服务器.VPS统计:- 2.5GHz 单核 CPU- 2GB 内存- OpenJDK 1.6(也尝试过 Sun JDK 1.7)

I am running a java server on a CentOS 5.4 VPS. VPS stats: - 2.5GHz single core CPU - 2GB of RAM - OpenJDK 1.6 (tried Sun JDK 1.7 also)

我在 java 进程中遇到了非常高的 CPU 使用率.然后我去尝试分析java进程以查看导致速度变慢的原因.我发现简单的方法(如 Random.nextInt(): 787ms)完成一次调用需要 1000 毫秒.大多数方法不应该花费这么长时间,并且会导致我的服务器上的 CPU 使用率非常高.CentOS 有什么问题吗?还是Java?还是我的 VPS 上有什么地方没有正确配置?

I have been experiencing very high CPU usages from the java process. I then went and tried profiling the java process to see what was causing the slow down. I found that simple methods (like Random.nextInt(): 787ms) were taking 1000's of miliseconds to finish one call. Most of the methods should not take this long and are causing very high CPU usage on my server. Is this something wrong with CentOS? or Java? or is there something that I have not correctly configured on my VPS?

推荐答案

不要在源代码中添加计时,而是尝试使用像 BTrace 这样的 Java 代理:http://kenai.com/projects/btrace 这将使您获得所需的信息,而不会弄乱您的应用程序源代码.

Instead of adding timings to your source code, try using a java agent like BTrace: http://kenai.com/projects/btrace which will let you get hold of the information you want, but without messing up your applications source code.

BTrace 可以与可视化工具结合使用,例如 EurekaJ,(我创建的一个用于可视化 BTtrace 输出的项目):http://eurekaj.haagen.name

BTrace can be coupled with a visualizer, such as EurekaJ, (a project I have created to visualize BTtrace output): http://eurekaj.haagen.name

还提供其他商业分析选项,例如 JProfiler 或 YourKit,但它们确实带有价格标签.

Other commercial profiling options are also available, such as JProfiler or YourKit, but they do come with a price tag.

这篇关于java方法的执行时间长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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