Skip to content

Commit bfc35ee

Browse files
authored
Merge pull request #483 from nicholassm/master
Add JMH benchmark to measure multi-producer batch publication performance.
2 parents f0a1d60 + 24fb16f commit bfc35ee

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/jmh/java/com/lmax/disruptor/MultiProducerSingleConsumer.java

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.openjdk.jmh.annotations.BenchmarkMode;
1010
import org.openjdk.jmh.annotations.Fork;
1111
import org.openjdk.jmh.annotations.Mode;
12+
import org.openjdk.jmh.annotations.OperationsPerInvocation;
1213
import org.openjdk.jmh.annotations.OutputTimeUnit;
1314
import org.openjdk.jmh.annotations.Scope;
1415
import org.openjdk.jmh.annotations.Setup;
@@ -32,6 +33,7 @@ public class MultiProducerSingleConsumer
3233
private RingBuffer<SimpleEvent> ringBuffer;
3334
private Disruptor<SimpleEvent> disruptor;
3435
private static final int BIG_BUFFER = 1 << 22;
36+
private static final int BATCH_SIZE = 100;
3537

3638
@Setup
3739
public void setup(final Blackhole bh)
@@ -57,6 +59,21 @@ public void producing()
5759
ringBuffer.publish(sequence);
5860
}
5961

62+
@Benchmark
63+
@Threads(4)
64+
@OperationsPerInvocation(BATCH_SIZE)
65+
public void producingBatch()
66+
{
67+
long hi = ringBuffer.next(BATCH_SIZE);
68+
long lo = hi - (BATCH_SIZE - 1);
69+
for (long sequence = lo; sequence <= hi; sequence++)
70+
{
71+
SimpleEvent simpleEvent = ringBuffer.get(sequence);
72+
simpleEvent.setValue(0);
73+
}
74+
ringBuffer.publish(lo, hi);
75+
}
76+
6077
@TearDown
6178
public void tearDown()
6279
{

0 commit comments

Comments
 (0)