java 方法的执行时间较长
我正在 CentOS 5.4 VPS 上运行 java 服务器。 VPS统计: - 2.5GHz单核CPU - 2GB 内存 - OpenJDK 1.6(也尝试过 Sun JDK 1.7)
我一直在 java 进程中遇到非常高的 CPU 使用率。然后我尝试分析 java 进程,看看是什么导致速度变慢。我发现简单的方法(如 Random.nextInt(): 787ms)需要 1000 毫秒才能完成一次调用。大多数方法不应花费这么长时间,并且会导致我的服务器上的 CPU 使用率非常高。这是 CentOS 有问题吗?还是Java?或者我的 VPS 上有什么配置不正确?
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)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要在源代码中添加计时,而是尝试使用 BTrace 之类的 Java 代理: http://kenai.com/projects/ btrace 可以让您获取所需的信息,但不会弄乱您的应用程序源代码。
BTrace 可以与可视化工具结合使用,例如 EurekaJ(我创建的一个用于可视化 BTtrace 输出的项目): http://eurekaj .haagen.name
还可以使用其他商业分析选项,例如 JProfiler 或 YourKit,但它们确实带有价格标签。
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 can be coupled with a visualizer, such as EurekaJ, (a project I have created to visualize BTtrace output): http://eurekaj.haagen.name
Other commercial profiling options are also available, such as JProfiler or YourKit, but they do come with a price tag.
当您测量程序内的处理时间时,您能否重现您的计时,即类似以下内容:
另外,“当 Java 不占用 97% 的 CPU 时它很快”是什么意思?为什么Java首先占据了97%?是否有多个线程在运行?您的计算是短期运行还是长期运行?
Can you reproduce your timings when you measure the processing time within the program, i.e. something like the following:
Also, what do you mean by "it is fast when Java is not taking 97% of the CPU"? Why is Java taking the 97% in the first place? Are there multiple threads running? Is your computation short or long running?