JavaEar 专注于收集分享传播有价值的技术资料

为什么JMH会运行不同的叉子? (Why does JMH run different forks?)

I am using the JMH benchmarking framework (http://openjdk.java.net/projects/code-tools/jmh/) to run benchmarks on my code. My understanding is that JMH forks the JVM multiple times during benchmarking in order to discard any profiles built up by the just-in-time (JIT) profiling performed by the JVM during execution.

I understand why this is useful in some cases such as the below (copied verbatim from http://java-performance.info/jmh/):

By default JHM forks a new java process for each trial (set of iterations). This is required to defend the test from previously collected “profiles” – information about other loaded classes and their execution information. For example, if you have 2 classes implementing the same interface and test the performance of both of them, then the first implementation (in order of testing) is likely to be faster than the second one (in the same JVM), because JIT replaces direct method calls to the first implementation with interface method calls after discovering the second implementation.

However, in the case where you are benchmarking the same code repeatedly is there any advantage to running say 10 forks of 20 iterations each instead of 1 fork with 200 iterations?

Many Thanks,

Danny

1个回答

    最佳答案

  1. 英文原文

    Some people insist that another problem solved by using forks is run-to-run variance: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

    However, any serious engineer must be able to exercise sufficient control over the benchmarking environment to eliminate any difference between runs. It is disheartening to see people using forks to overcome their laziness or lack of understanding of how their benchmarks are actually executed.


    中文翻译

    有些人坚持认为使用分叉解决的另一个问题是逐次运行的差异: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main /java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

    但是,任何认真的工程师必须能够对基准测试环境进行足够的控制,以消除运行之间的任何差异。看到人们使用货叉来克服他们的懒惰或对他们的基准实际执行方式缺乏了解,这是令人沮丧的。

    Some people insist that another problem solved by using forks is run-to-run variance: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

    However, any serious engineer must be able to exercise sufficient control over the benchmarking environment to eliminate any difference between runs. It is disheartening to see people using forks to overcome their laziness or lack of understanding of how their benchmarks are actually executed.

    有些人坚持认为使用分叉解决的另一个问题是逐次运行的差异: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main /java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

    但是,任何认真的工程师必须能够对基准测试环境进行足够的控制,以消除运行之间的任何差异。看到人们使用货叉来克服他们的懒惰或对他们的基准实际执行方式缺乏了解,这是令人沮丧的。