开发者

Large CPU usage on a java process under Linux

开发者 https://www.devze.com 2023-04-04 22:22 出处:网络
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.

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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号