process CPU time

We are using JAVA program and strange thing is it takes 100% CPU when not in use.

The program function is to stream a file on output port (one direction). It checks one directory and when there is a file in it, starts.

While it is streaming the CPU usage is normal, about 20%.

But, if there is nothing to do, it takes all available CPU.

What could it be?
Thanks.

Poor coding ?

1 Like

hm, yes, probably. software version is 1.0
but its quite expensive, and I'm not sure if we can ask for update.

I was hoping there were some easy fix, or perhaps that maybe sometimes Solaris reports 100% usage even if it isn't. (server worked for months under such load) so that we could simply ignore it.

Most certainly bad programming from your description. This program IMO checks the directory continuously, without a delay for the required file, instead of checking every second, or waiting for an OS trigger. And no, you can't add that functionality afterwards.

But if it's so expensive, instead of asking for an update demand it, as this is certainly a bug.

1 Like

If you are ready for hacks as workaround, it would probably be easy to slow down your process when it has nothing to process. There would be several approaches to do it like an interposing library or a dtrace script.

If you can have any sort of return code when the file(s) are uploaded, you could write a simple script that kills the program once a file is uploaded. Then build a cronjob that starts it every minutes if it is not already running.

Dirt cheap and gets things done faster then a monkey coder.

It can also be done fairly easily with projects.

1 Like

If you think about capping CPU usage, that would be less efficient and possibly hurting the application performance but certainly less hackish too.

Well, if the OP capped the application to say 30%, it shouldn't hurt it as during normal operation it is not exceeding 20% of CPU utilization. Of course it is a temporary solution :wink:

It's funny because we actually discussed about binding a process to a CPU this morning at the office.

Solaris Processor Sets Made Easy

This is pretty interesting. In fact, if you have an high end T or M you could bind it to 1 thread (aka VCPU or core ... whatever they call it now).

bartus' idea of project is also interesting and in fact, we discussed it to this morning ...

Chapter�2 Projects and Tasks (Overview) (System Administration Guide: Oracle Solaris Containers-Resource Management and Oracle Solaris Zones)

Anyway, this was just FYI. Hope it helps.