Skip to main content

Need to reduce Java application's CPU utilization

5 replies [Last post]
garnet4
Offline
Joined: 2008-04-21
Points: 0

Hi,

I wrote a Java application for creating search indexes. When run, this application utilizes almost 100% of CPU until it ends. This application performs lots of IO operations. I need to reduce its CPU usage to about 50-60% sacrificing the speed (i.e., it is fine if it takes an extra 10-15 minutes to finish).

So far, I tried changing different Java HotSpot VM options but still couldn't reduce the CPU usage.

"ps -p PID -o pid,nlwp" shows me that the applications NLWP is 13.

Could any one offer advice regarding reducing CPU usage?[/b]

Thanks for any help,
Jon

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fuerte2
Offline
Joined: 2005-02-28
Points: 0

Usually if application does a lot of IO, then it can't use 100% CPU, because it is waiting for IO completion. Also it would be better to run your application in lower priority, if CPU utilization is a problem. Adding extra sleeps or delays does not sound like a solution. If CPU is there, why not use it to the full?

sarobenalt
Offline
Joined: 2005-01-01
Points: 0

Actually, if an application is truly I/O bound, a sleep (even a short one) can be fairly effective. Apps like this often wait for the I/O to complete in a tight spin loop. It is the spin loop which consumes all of the CPU resources doing nothing. A Thread.sleep(1) in the middle of that loop can reduce the CPU drastically without much impact on the application performance. A longer sleep than 1 ms can reduce it even further.

Of course, if the CPU is actually working that hard on real stuff, not spinning in a loop waiting for I/O to complete, you won't see as dramatic an effect.

Either way, it's an easy check to do.

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

> Apps like this often wait for the I/O to complete in
> a tight spin loop. It is the spin loop which consumes
> all of the CPU resources doing nothing.
Sorry, but I don't know any app that does ugly stuff like this.
At least tradidional blocking IO solves all of those problems :)

lg Clemens

mthornton
Offline
Joined: 2003-06-10
Points: 0

Sleep for 100ms every 200ms.

greg_helton
Offline
Joined: 2006-09-01
Points: 0

I would benchmark the code against Lucene and, if Lucene is more efficient, replace the code with Luncene's index build and search.