RFR: 7903554: JMH: add Threads.HALF_MAX constant

Aleksey Shipilev shade at openjdk.org
Fri Sep 8 08:17:10 UTC 2023


On Fri, 8 Sep 2023 03:42:02 GMT, Sergey Kuksenko <skuksenko at openjdk.org> wrote:

> add Threads.HALF_MAX constant equals to "Runtime.getRuntime().availableProcessors()/2"

RFE does not really say what is the target use case for this one. More comments:

jmh-core-it/src/test/java/org/openjdk/jmh/it/threads/HalfMaxThreadCountTest.java line 2:

> 1: /*
> 2:  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.

Years seem wrong.

jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java line 400:

> 398:             }
> 399:             if (threads == Threads.HALF_MAX) {
> 400:                 threads = Math.max(1, cpuCount / 2);

I'd say we just round half-up: `(cpuCount + 1) / 2`, which makes a better choice for odd number of CPUs, including `1`.

jmh-core/src/main/java/org/openjdk/jmh/runner/options/CommandLineOptions.java line 134:

> 132: 
> 133:         OptionSpec<Integer> optThreads = parser.accepts("t", "Number of worker threads to run with. 'max' means the " +
> 134:                 "maximum number of hardware threads available on the machine, figured out by JMH itself. 'half_max' means 'max/2'" +

I'd suggest we do `halfmax` instead of enum-style-but-not-really-enum `half_max`.

-------------

PR Review: https://git.openjdk.org/jmh/pull/118#pullrequestreview-1616929890
PR Review Comment: https://git.openjdk.org/jmh/pull/118#discussion_r1319520036
PR Review Comment: https://git.openjdk.org/jmh/pull/118#discussion_r1319523410
PR Review Comment: https://git.openjdk.org/jmh/pull/118#discussion_r1319525701


More information about the jmh-dev mailing list