Instructions for setting up multithreaded tests?
Aleksey Shipilev
aleksey.shipilev at oracle.com
Wed Apr 27 10:02:24 UTC 2016
On 04/27/2016 12:53 PM, Millies, Sebastian wrote:
> not sure if I am doing this right. I want a test that has both global
> state (shared across benchmark methods) and local ( new for each
> iteration). I want the test to be multi-threaded, so that each
> iteration is executed by multiple threads. Thus I will get contention
> on the local state within each iteration.
What's the problem for constructing two state objects, one with
Scope.Benchmark where the shared data is put, and one with Scope.Thread,
where the local data resides?
http://hg.openjdk.java.net/code-tools/jmh/file/39ed8b3c11ce/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_03_States.java
You can reference *both* states in your @Benchmark arguments.
You can even make these states dependent on each other, in case local
threads have to work on the subset of the shared state, as
JMHSample_29_StatesDAG explains:
http://hg.openjdk.java.net/code-tools/jmh/file/39ed8b3c11ce/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_29_StatesDAG.java
> I am having particular trouble understanding the interaction between
> the setup levels and the scopes.
They are pretty much orthogonal? Setup level tells when to run
@Setup/@TearDown. Scope defines what threads have access to state
object, and, by extension, what threads are eligible to run
@Setup/@TearDown on them.
-Aleksey
More information about the jmh-dev
mailing list