Single Consumer Multiple Producers Benchmark

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Dec 4 09:30:05 PST 2013


Hi,

On 12/04/2013 09:05 PM, Ron Pressler wrote:
> Say I want to benchmark a queue implementation with multiple
> producers and a single consumer. I can limit the consumer’s method
> with @GroupThreads(1), but I want the producer subgroup to use all
> remaining available threads. Is that possible?

Depends on what you mean by "remaining available".

Basically, you have two options:

 a) If you want to juggle the thread subgroup distribution, make the
@Group out of two methods, and play with "-tg 1,${X}" on the command
line, where $X is the number of threads you want in the second subgroup.

 b) If you want to autodetect the available CPU count on your machine,
then it starts to get a bit trickier. You need to use Java API to push
that value into the workload, something like this:

         int maxThreads = Runtime.getRuntime().availableProcessors();
         Options opts = new OptionsBuilder()
                 .include(".*")
                 .threadGroups(1, maxThreads - 1)
                 .build();

         RunResult runResult = new Runner(opts).runSingle();

  The complete example is available here [1].

In both cases, the total number of threads will automatically adjust to
have a full group.

-Aleksey.

[1]
http://hg.openjdk.java.net/code-tools/jmh/file/f39c77f5b84a/jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java


More information about the jmh-dev mailing list