应用程序服务器过度使用 CPU 的原因

发布于 2024-11-10 08:35:48 字数 224 浏览 5 评论 0原文

我们正在JBOSS中使用oracle运行一个JAVA应用程序。我们使用了Seam和Hibernate框架。我们面临的问题是,当我们启动应用程序服务器时,CPU利用率增加,一小时后我们发现CPU利用率接近90% .这很奇怪,我无法确定问题所在。

请帮忙。提前致谢。

干杯, Dwarak在此处输入图像描述

We are running a JAVA application in JBOSS with oracle.We have used Seam and Hibernate frameworks.The problem we are facing is,when we start tha application server the cpu utlizations increase and after one hour we found that CPU utilizaiton is close to 90%.It is bizarred and I am not able to identify the problem.

Please Help.Thanks in Advance.

Cheers,
Dwarakenter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅语花开 2024-11-17 08:35:48

理想情况下,您可以使用分析器来追踪问题。如果您无法在其所在的环境(例如生产环境)中使用探查器,请尝试在其他地方重现它并在那里附加探查器。但这通常很困难,所以这里有一个我多次使用过的技巧,用于从命令行查找生产中 CPU 使用率的原因:

watch -n1 'jstack [pid] | grep -A 1 RUNNABLE | grep -v RUNNABLE | grep -v \\-\\- | grep -v socketRead0 | grep -v socketAccept`

如果您短时间观看此内容,您可能会看到一些常见的方法叫。接下来将完整的 jstack 输出获取到文件中:

jstack [pid] > jstack.log

现在在文件中搜索您经常看到的方法之一。从堆栈跟踪中,您通常可以找到负责 CPU 消耗的代码。如果没有任何显示,那么也许您的时间将用于过多的垃圾收集,您只需要增加内存即可。您可以使用:

`jmap -heap [pid]`

更好地了解内存使用情况。更好的是,您可以附加 jvisualvm 或商业广告Profiler(例如 YourKit)随着时间的推移以图形方式查看它。我有时也使用过 watch -n1 'jmap -heap [pid]' 。

Ideally you can use a profiler to track down the problem. If you can't use a profiler in the environment it's in (like production) then try to reproduce it somewhere else and attach a profiler there. Often that can be difficult though, so here's a trick I've used a number of times to find the cause of CPU utilization in production from the command line:

watch -n1 'jstack [pid] | grep -A 1 RUNNABLE | grep -v RUNNABLE | grep -v \\-\\- | grep -v socketRead0 | grep -v socketAccept`

If you watch this for a short period of time you might see some common methods being called. Next grab a full jstack output to a file:

jstack [pid] > jstack.log

Now search the file for one of the methods that you saw showing up frequently. From its stack trace you can usually find the code responsible for grinding the CPU. If nothing shows up then perhaps your time is going to excessive garbage collection and you simply need to increase memory. You can use:

`jmap -heap [pid]`

To get a better idea of memory usage. Better yet you can attach jvisualvm or a commercial profiler (like YourKit) to see it graphically over time. I've also used watch -n1 'jmap -heap [pid]' on occasion.

叹沉浮 2024-11-17 08:35:48
  • 首先,确保是 JBoss 执行的进程占用了 CPU。如果您使用 Linux,请使用 top 命令,或者在 Windows 中,使用任务管理器来监视运行 JBoss 的 java 进程的 CPU 利用率。
  • 如果是这种情况,请查看服务器日志文件,看看在此期间发生了什么。它是否真的在做一些重要的工作,或者当您的应用程序空闲时 CPU 利用率是否很高?
  • 确保系统中有足够的可用内存供操作系统使用。如果 jboss 进程耗尽了所有可用内存,操作系统将没有足够的内存用于其自身的活动,这可能会导致系统崩溃(将页面换入或换出虚拟内存,从而占用 CPU)。
  • 确保为 JVM 提供了足够的堆内存。您可以在 JBoss bin 目录中的 run.conf 文件中增加这些值。当堆大小对于您的应用程序而言太小时,可能会发生颠簸。另外,如果堆大小太大(例如超过 2GB),那么 GC 堆所花费的时间也会占用您的 CPU。
  • 当 JBoss 运行时检查机器上的磁盘 I/O。如果您将日志级别设置为非常低的值,并且 JBoss 最终写入大量日志文件,则也可能导致 CPU 使用率较高(用于写入日志文件!)。
  • 如果您使用的是 JDK 1.5.0.10,请查看此链接。 我的 JBoss 服务器达到 100% Linux 上的 SYS CPU;是什么导致了这种情况?

如果以上都没有帮助,那么最后的办法就是使用分析工具。我建议 JProfiler 或 Yourkit Profiler(商业版,但有 30 天试用期),它们非常用户友好。

  • First off, make sure that it's the process which is executed by JBoss which hogs up the CPU. If you are using Linux use top command, or in Windows, use Task Manager to monitor the CPU utilization by java process which runs JBoss.
  • If that is the case, take a look at your server log files to see what happens during this time. Is it really doing some significant work, or is the CPU utilization is high when your application is idling also ?
  • Make sure that you have enough free memory in the system for OS. If the jboss process eats up all the free memory, the OS will not have enough memory for it's own activities, which could lead up to thrashing (swapping pages in and out of virtual memory which eats up CPU).
  • Make sure you have given adequate heap memory to JVM. You can increase these values in run.conf file in the bin directory of JBoss. When the heap size is too small for your application, thrashing can occur. Also, if the heap size is too large (over 2GB for example), then the time taken to GC the heap will also hog up your CPU.
  • Check Disk I/O on your machine when JBoss runs. If you set your log levels to very low values, and if JBoss ends up writing massive log files, that could also lead to high CPU usage (for writing log files !).
  • If you are using JDK 1.5.0.10, take a look at this link. My JBoss server hits 100% SYS CPU on Linux; what can cause this?

If nothing above helps, the last resort is to go for a profiling tool. I suggest JProfiler or Yourkit Profiler (Commercial, but 30-day trail available) which is very user-friendly.

作业与我同在 2024-11-17 08:35:48

使用分析器来查找问题。如果使用 Oracle Java 6,请从 JDK 中的 jvisualvm 启动。

Use a profiler to find the problem. If using Oracle Java 6, start with jvisualvm in the JDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文