Skip to content

Commit

Permalink
Merge pull request #483 from nicholassm/master
Browse files Browse the repository at this point in the history
Add JMH benchmark to measure multi-producer batch publication performance.
  • Loading branch information
grumpyjames committed Sep 11, 2024
2 parents f0a1d60 + 24fb16f commit bfc35ee
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/jmh/java/com/lmax/disruptor/MultiProducerSingleConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
Expand All @@ -32,6 +33,7 @@ public class MultiProducerSingleConsumer
private RingBuffer<SimpleEvent> ringBuffer;
private Disruptor<SimpleEvent> disruptor;
private static final int BIG_BUFFER = 1 << 22;
private static final int BATCH_SIZE = 100;

@Setup
public void setup(final Blackhole bh)
Expand All @@ -57,6 +59,21 @@ public void producing()
ringBuffer.publish(sequence);
}

@Benchmark
@Threads(4)
@OperationsPerInvocation(BATCH_SIZE)
public void producingBatch()
{
long hi = ringBuffer.next(BATCH_SIZE);
long lo = hi - (BATCH_SIZE - 1);
for (long sequence = lo; sequence <= hi; sequence++)
{
SimpleEvent simpleEvent = ringBuffer.get(sequence);
simpleEvent.setValue(0);
}
ringBuffer.publish(lo, hi);
}

@TearDown
public void tearDown()
{
Expand Down

0 comments on commit bfc35ee

Please sign in to comment.