2

我一直在研究 jmh 实现“多线程”基准的方式。据我了解,注释@Group("Identifier")@GroupThreads(thread_number)启用并行运行同一组内的基准。

@Benchmark
@Group("parallel")
@GroupThreads(1)
public void benchmark_1() {
    while(true) {}
}

@Benchmark
@Group("parallel")
@GroupThreads(1)
public void benchmark_2() {
    while(true) {}
}

使用 CPU 监视器,我得到两个 CPU 已完全使用。我想知道跑步者如何解释这些注释。

4

1 回答 1

5

您是否尝试过阅读 Javadocs?那些不回答问题的人吗?

例如@Group说:

 * <p>Multiple {@link Benchmark} methods can be bound in the execution group
 * to produce the asymmetric benchmark. Each execution group contains of one
 * or more threads. Each thread within a particular execution group executes
 * one of {@link Group}-annotated {@link Benchmark} methods. The number of
 * threads executing a particular {@link Benchmark} defaults to a single thread,
 * and can be overridden by {@link GroupThreads}.</p>
 *
 * <p>Multiple copies of an execution group may participate in the run, and
 * the number of groups depends on the number of worker threads requested.
 * JMH will take the requested number of worker threads, round it up to execution
 * group size, and then distribute the threads among the (multiple) groups.
 * Among other things, this guarantees fully-populated execution groups.</p>

 * <p>For example, running {@link Group} with two {@link Benchmark} methods,
 * each having {@link GroupThreads}(4), will run 8*N threads, where N is an
 * integer.</p>

因此,@Group产生一个非对称基准,@GroupThreads控制组内线程的分布(-tg ...在 CLI 中称为它)。@Threads说总共要运行多少个线程(-t ...在 CLI 中配音)。

于 2015-05-08T07:36:26.097 回答