The Source for Java Technology Collaboration

Home » java.net Forums » Performance » General Performance Discussion

Thread: Need to reduce Java application's CPU utilization

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Apr 24, 2008 3:44 PM by: linuxhippy Threads: [ Previous | Next ]
garnet4

Posts: 1
Need to reduce Java application's CPU utilization
Posted: Apr 21, 2008 9:27 PM
  Click to reply to this thread Reply

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?

Thanks for any help,
Jon

mthornton

Posts: 528
Re: Need to reduce Java application's CPU utilization
Posted: Apr 22, 2008 2:08 AM   in response to: garnet4
  Click to reply to this thread Reply

Sleep for 100ms every 200ms.

greg_helton

Posts: 1
Re: Need to reduce Java application's CPU utilization
Posted: Apr 22, 2008 11:56 AM   in response to: mthornton
  Click to reply to this thread Reply

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

fuerte2

Posts: 7
Re: Need to reduce Java application's CPU utilization
Posted: Apr 23, 2008 2:31 AM   in response to: garnet4
  Click to reply to this thread Reply

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

Posts: 3
Re: Need to reduce Java application's CPU utilization
Posted: Apr 23, 2008 1:45 PM   in response to: fuerte2
  Click to reply to this thread Reply

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

Posts: 646
Re: Need to reduce Java application's CPU utilization
Posted: Apr 24, 2008 3:44 PM   in response to: sarobenalt
  Click to reply to this thread Reply

> 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




 XML java.net RSS