RFR: 7903492: JMH: Infrastructure code should yield occasionally for virtual executor to make progress
old driver
duke at openjdk.org
Sat Dec 21 03:02:48 UTC 2024
On Thu, 8 Jun 2023 16:02:44 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
> Virtual executor can starved out by JMH infra code that busy loops. GHAs that are running with low core machines, where we see occasional timeouts with tests that do not make progress on their own. One of those tests require an explicit `Thread.yield` in its busy loop.
>
> This also affects the actual measurement loop, I think, but working it out regressing performance for every other executor would take a while. It would also be arguably a broken benchmark to try and run with more threads than the platform threads are available.
With JMH version 1.37, the virtual executor still got stucked on my test machine with JDK-21 or JDK-23, with following code:
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.concurrent.ConcurrentHashMap;
@State(Scope.Benchmark)
@Warmup(iterations = 1, time = 1)
@Measurement(iterations = 1, time = 1)
@Fork(2)
public class T1221 {
private static final ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<Object, Object>();
@Benchmark
@Threads(120)
public void testMap(Blackhole blackhole) {
Object key = new Object();
map.put(key, new Object());
blackhole.consume(map);
blackhole.consume(map.remove(key));
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(T1221.class.getSimpleName())
.resultFormat(ResultFormatType.JSON)
.jvmArgs("-Djmh.executor=VIRTUAL")
.build();
new Runner(opt).run();
}
}
Am I miss configured anything in the code?
-------------
PR Comment: https://git.openjdk.org/jmh/pull/111#issuecomment-2557966871
More information about the jmh-dev
mailing list