简体   繁体   English

Linux下Java进程上的大量CPU使用率

[英]Large CPU usage on a java process under Linux

I am running into trouble to determine what is wrong with my software. 我遇到麻烦来确定我的软件出了什么问题。 The situation is; 情况是; -The program is always running on background and every X minutes performs some actions. -该程序始终在后台运行,每隔X分钟执行一些操作。 -Right now it is set to check every 1 minute a certain directory and see if there are new files in it. -现在,它设置为每1分钟检查一次某个目录,并查看其中是否有新文件。 -If there are new files, they are processed and moved somewhere else. -如果有新文件,则将它们处理并移动到其他位置。 -If not, it simply logs the event and goes idle again. -如果不是,则只记录事件并再次进入空闲状态。

I Assume that when new files appear, CPU usage can be somewhat high. 我假设出现新文件时,CPU使用率可能会很高。 The problem comes when, even if I dont put new files in the directory for many days, the CPU usage will raise to ~90% every minute it checks for new entrys, then after some seconds, return back to <1% usage. 问题来了,即使我很多天都没有在目录中放置新文件了,它也会在检查新条目时每分钟将CPU使用率提高到〜90%,然后在几秒钟后恢复到<1%使用率。

The same process under windows seems somehow stable, staying always on low cpu usage. Windows下的相同进程似乎在某种程度上很稳定,始终保持低CPU使用率。

If I monitor the CPU activty monthly, I can see that the average CPU usage for my java process keeps growing up (without putting new files to 'activate' the rest of the process), and I have to restart the process for it to return to lower CPU usage levels. 如果我每月监视一次CPU活动,我可以看到我Java进程的平均CPU使用率一直在增长(没有将新文件“激活”其余进程),并且我必须重新启动进程才能返回降低CPU使用率水平。

I really dont happen to understand this behaviour, so I dont really know what may be affecting this. 我真的不是很了解这种行为,所以我真的不知道什么可能会影响这种行为。

If the log file is somewhat 'big', like 10-20mb would it require that much cpu to log a new entry every minute? 如果日志文件有点“大”,例如10-20mb,那么每分钟要记录一个新条目是否需要那么多的cpu?

If there are many libraries loaded in the classpath for this process, will the cpu usage be increased even though many of this libraries wont be used most all the time? 如果为此过程在类路径中加载了许多库,那么即使大多数时间都不会使用许多此类库,CPU使用率还会增加吗?

Excuse me if I haven't been very clear on my question, I am somewhat new to this. 对不起,如果我不清楚我的问题,我对此有些陌生。

Thanks every one in advance, regards. 预先感谢每一位,问候。

--edit-- I note your advices, I will do some monitoring and I will post some code / results to share with you and see what can you come up with! --edit--我注意到您的建议,我将进行一些监视,并发布一些代码/结果与您分享,看看您能提出什么建议!

I am really lost right now! 我现在真的迷路了!

I your custom monitoring code is causing a problem, you could always use something standard like Apache Commons IO's FileAlterationMonitor . 如果您的自定义监视代码引起了问题,则可以始终使用诸如Apache Commons IO的FileAlterationMonitor之类的标准 It's simple to implement and it might be faster than fixing your current code. 它实现起来很简单,而且可能比修复当前代码要快。

Are you talking about a simple console application or a swing/awt app ? 您是在谈论简单的控制台应用程序还是swing / awt应用程序?

Is the application run every minute via OS underlying at schedule or it's a simple server process ? 该应用程序是否按时间表通过底层操作系统每分钟运行,还是一个简单的服务器进程?

If the process is run as a server how do you launch the VM ? 如果该进程作为服务器运行,则如何启动VM? (server VM or client VM - -server switch on cmd line) (服务器VM或客户端VM--在cmd行上的服务器开关)

You may check also your garbage collector, sometimes logging framework use up too many object without releasing their references. 您还可以检查您的垃圾收集器,有时日志记录框架会用完太多对象而没有释放它们的引用。

Regards 问候

M. M.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM