简体   繁体   English

@Group和@GroupThreads在jmh中指的是什么?

[英]What does @Group and @GroupThreads refer to in jmh?

I have been looking at the way jmh implements the "multithreaded" benchmarks. 我一直在研究jmh实现“多线程”基准测试的方式。 From my understanding, the annotations @Group("Identifier") and @GroupThreads(thread_number) enable running in parallel the benchmarks that are within the same Group. 据我了解,注释@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) {}
}

Using the CPU monitor, I get that two CPU's are fully used. 使用CPU监视器,我发现两个CPU已被完全使用。 I would like to know how does the runner interpret those annotations. 我想知道跑步者如何解释这些注释。

Have you tried reading Javadocs? 您是否尝试阅读Javadocs? Are those not answering the question? 那些没有回答这个问题吗?

Eg @Group says: 例如@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>

So, @Group produces an asymmetric benchmark, @GroupThreads controls the distribution of threads within the group ( -tg ... in CLI dubs it). 所以, @Group产生不对称基准, @GroupThreads控制线程组成的组中的分布( -tg ...在CLI配音它)。 @Threads say how many threads to run in total ( -t ... in CLI dubs it). @Threads表示总共要运行多少个线程(CLI中的-t ...将其@Threads )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM