Linux 下 java 进程 CPU 使用率过高

发布于 2024-12-04 18:29:42 字数 680 浏览 3 评论 0原文

我在确定我的软件出了什么问题时遇到了麻烦。 情况是; -该程序始终在后台运行,并且每 X 分钟执行一些操作。 - 现在设置为每 1 分钟检查某个目录并查看其中是否有新文件。 - 如果有新文件,它们将被处理并移动到其他地方。 - 如果没有,它只是记录事件并再次空闲。

我假设当新文件出现时,CPU 使用率可能会有点高。 问题来了,即使我很多天没有在目录中放入新文件,CPU 使用率每分钟检查新条目也会上升到约 90%,然后几秒钟后,返回到 <1% 使用率。

Windows 下的相同进程似乎在某种程度上稳定,始终保持较低的 cpu 使用率。

如果我每月监控 CPU 活动,我可以看到 java 进程的平均 CPU 使用率不断增长(没有放置新文件来“激活”进程的其余部分),并且我必须重新启动该进程才能返回以降低 CPU 使用率。

我真的不明白这种行为,所以我真的不知道什么可能会影响这种行为。

如果日志文件有点“大”,比如 10-20mb,是否需要那么多 cpu 每分钟记录一个新条目?

如果该进程的类路径中加载了许多库,那么即使其中许多库不会一直被使用,CPU 使用率是否会增加?

抱歉,如果我的问题不太清楚,我对此有点陌生。

预先感谢每一个人,问候。

- 编辑 - 我注意到你的建议,我会做一些监控,我会发布一些代码/结果与你分享,看看你能想出什么!

我现在真的迷失了!

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.
-Right now it is set to check every 1 minute a certain directory and see if there are new files in it.
-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.
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.

The same process under windows seems somehow stable, staying always on low cpu usage.

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.

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?

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?

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!

I am really lost right now!

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

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

发布评论

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

评论(2

五里雾 2024-12-11 18:29:42

如果您的自定义监控代码导致了问题,您始终可以使用 Apache Commons IO 之类的标准 文件更改监视器。它实现起来很简单,并且可能比修复当前代码更快。

I your custom monitoring code is causing a problem, you could always use something standard like Apache Commons IO's FileAlterationMonitor. It's simple to implement and it might be faster than fixing your current code.

饮湿 2024-12-11 18:29:42

您是在谈论简单的控制台应用程序还是 swing/awt 应用程序?

应用程序是通过底层操作系统按计划每分钟运行一次还是一个简单的服务器进程?

如果该进程作为服务器运行,如何启动虚拟机? (服务器虚拟机或客户端虚拟机 - -服务器在命令行上切换)

您还可以检查垃圾收集器,有时日志记录框架会使用太多对象而不释放它们的引用。

问候

M。

Are you talking about a simple console application or a swing/awt app ?

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 ? (server VM or client VM - -server switch on cmd line)

You may check also your garbage collector, sometimes logging framework use up too many object without releasing their references.

Regards

M.

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