High Execution time on java methods
I am running a java server on a CentOS 5.4 VPS. VPS stats: - 2.5GHz single core CPU - 2GB of RAM - OpenJDK 1.6 (tried Sun JDK 1.7 also)
I have been experiencing very high CPU usages from the java process. I then went and tried profiling the java process to see what was causing the slow down. I found that simple methods (like Random.nextInt(): 787ms) were taking 1000's of miliseconds to finish one call. Most of the methods should not take this long and are causing very high CPU usage on my server. Is this something wrong with Ce开发者_JAVA百科ntOS? or Java? or is there something that I have not correctly configured on my VPS?
Instead of adding timings to your source code, try using a java agent like BTrace: http://kenai.com/projects/btrace which will let you get hold of the information you want, but without messing up your applications source code.
BTrace can be coupled with a visualizer, such as EurekaJ, (a project I have created to visualize BTtrace output): http://eurekaj.haagen.name
Other commercial profiling options are also available, such as JProfiler or YourKit, but they do come with a price tag.
Can you reproduce your timings when you measure the processing time within the program, i.e. something like the following:
long start = System.currentTimeMillis();
/* Your code */
[...]
long time = System.currentTimeMillis() - start;
System.out.println("Measurement: " + time);
Also, what do you mean by "it is fast when Java is not taking 97% of the CPU"? Why is Java taking the 97% in the first place? Are there multiple threads running? Is your computation short or long running?
精彩评论