Search code examples
javaperformancetimegarbage-collectionexecution

Java Execution Time Peaks within a Loop


I have a loop with 701 iterations of similar complex calculations. I measured the execution time of each iteration for three runs. As you can see in the chart I'm getting strange peaks. Is there any common aproach which is able to explain these peaks without analyzing the code inside the loop. Execution Time

Is it possible that the gc is starting at these points and slow down the other parts?


Solution

  • It depends.

    If you don't want to analyze the code inside the loop you have to analyze at least the usage of memory during excution. For example if algorithm does not create many garbage and you have configured enough heap and you have chosen the right gc algorithm then the gc does not require any "stop the world".

    As first thing you have to activate gc logging (see here: http://www.oracle.com/technetwork/articles/javase/gcportal-136937.html) and check for gc peaks in correspondance to your time peaks.

    If you want to analyze the gc log you can use this tool http://www.tagtraum.com/gcviewer.html.

    Then follow the link posted from Turing85 about micro-benchmarks. It is more complete.