|
Replies:
5
-
Last Post:
Apr 24, 2008 3:44 PM
by: linuxhippy
|
Threads:
[
Previous
|
Next
]
|
|
|
|
|
|
Need to reduce Java application's CPU utilization
Posted:
Apr 21, 2008 9:27 PM
|
|
|
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
|
|
|
|
|
|
|
Re: Need to reduce Java application's CPU utilization
Posted:
Apr 22, 2008 2:08 AM
in response to: garnet4
|
|
|
Sleep for 100ms every 200ms.
|
|
|
|
|
|
|
|
Re: Need to reduce Java application's CPU utilization
Posted:
Apr 22, 2008 11:56 AM
in response to: mthornton
|
|
|
I would benchmark the code against Lucene and, if Lucene is more efficient, replace the code with Luncene's index build and search.
|
|
|
|
|
|
|
|
Re: Need to reduce Java application's CPU utilization
Posted:
Apr 23, 2008 2:31 AM
in response to: garnet4
|
|
|
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?
|
|
|
|
|
|
|
|
Re: Need to reduce Java application's CPU utilization
Posted:
Apr 23, 2008 1:45 PM
in response to: fuerte2
|
|
|
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.
|
|
|
|
|
|
|
|
Re: Need to reduce Java application's CPU utilization
Posted:
Apr 24, 2008 3:44 PM
in response to: sarobenalt
|
|
|
> 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
|
|
|
|
|