Using JMH to test virtual thread performance
Aleksey Shipilev
shade at redhat.com
Tue Feb 8 18:17:17 UTC 2022
On 2/8/22 15:02, Alan Bateman wrote:
> On 08/02/2022 00:22, Firouz Bharthania wrote:
>> Can JMH (Java Microbenchmarking Harness) be used for measuring virtual threads at this time, because I get high, unacceptable error margins when I run tests?
The "high, unacceptable error margins" might just be indicative that benchmark is very noisy. In
that case, no benchmark harness could possibly help.
> Aleksey may have some advice but I would expect it should be possible to
> create a runner that invokes org.openjdk.jmh.Main.main in the context of
> a virtual thread. I don't know if anyone has done that.
It is probably not a great idea to execute @Benchmark methods on virtual threads, because they are
using quite heavy synchronization, which AFAICS would just block the carrier thread in current
implementation? Anyhow, JMH allows overriding the ExecutorService that runs the benchmark threads,
not sure if it fits current Loom APIs:
https://github.com/openjdk/jmh/blob/85dfd3bf334159b0bc1acf1059cb6c505d0c95e4/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkHandler.java#L227-L234
--
Thanks,
-Aleksey
More information about the loom-dev
mailing list