Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set/restore context class loader around benchmark methods in JMH #421

Merged
merged 4 commits into from
Oct 11, 2023

Conversation

lbulej
Copy link
Member

@lbulej lbulej commented Oct 10, 2023

Wraps Benchmark interface methods with code that set and restores the context class loader for the current thread when running with JMH. This is because JMH option -t causes it to create more benchmark runners that invoke the Benchmark.run() method concurrently on a single benchmark instance, but do not replicate the context class loader of the (initial) main thread.

Even though this is not really supported (or intended) use of the Benchmark interface, the benchmarks should not crash because they fail to load their classes.

One other change is that the JMH wrappers now call setupBeforeEach() and tearDownAfterEach() after each measured method invocation as they should. This probably only affects runs with timed JMH iterations, during which JMH would invoke the measured method multiple times without calling the setup/tear-down methods.

Fixes #373

This is to make it more obvious that the right benchmark method
is called from the given JMH method.
This is what the Benchmark interface actually mandates. The fact that we were using
`Level.Iteration` instead of `Level.Invocation` was a result of conceptual mismatch.
The duration of the measured operations are in the hundreds of milliseconds or longer,
therefore `Level.Invocation` should not really be a problem.
Wraps `Benchmark` interface methods with code that set and restores the
context class loader for the current thread when running with JMH. This
is because JMH can be asked to create more benchmark runners that
invoke the `Benchmark.run()` method concurrently but do not replicate
the context class loader of the (initial) main thread.

Even though this is not really supported (or intended) use of the
`Benchmark` interface, the benchmarks should not crash because they
fail to load their classes.
@lbulej lbulej requested review from axel22 and farquet October 10, 2023 18:31
@lbulej lbulej marked this pull request as ready for review October 10, 2023 18:31
@lbulej lbulej merged commit 401de1c into master Oct 11, 2023
15 checks passed
@lbulej lbulej deleted the issue/373 branch October 11, 2023 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AkkaUct failing with error java.lang.ClassNotFoundException: akka.event.DefaultLoggingFilter
2 participants