Benchmarks now use package-level ring buffer; GOROUTINES is now explicit per test; allowing cleanup time between tests.
diff --git a/benchmark-disruptor/init_test.go b/benchmark-disruptor/init_test.go
index 8d4945b..960fdb7 100644
--- a/benchmark-disruptor/init_test.go
+++ b/benchmark-disruptor/init_test.go
@@ -1,6 +1,6 @@
package benchmarks
-import "runtime"
+import "time"
const (
RingBufferSize = 1024 * 64
@@ -8,8 +8,7 @@
ReserveOne = 1
ReserveMany = 16
ReserveManyDelta = ReserveMany - 1
+ DisruptorCleanup = time.Millisecond * 10
)
-func init() {
- runtime.GOMAXPROCS(2)
-}
+var ringBuffer = [RingBufferSize]int64{}
diff --git a/benchmark-disruptor/sample_consumer_test.go b/benchmark-disruptor/sample_consumer_test.go
index 61c5a0e..5f2a15c 100644
--- a/benchmark-disruptor/sample_consumer_test.go
+++ b/benchmark-disruptor/sample_consumer_test.go
@@ -3,12 +3,11 @@
import "fmt"
type SampleConsumer struct {
- ringBuffer *[RingBufferSize]int64
}
func (this SampleConsumer) Consume(lower, upper int64) {
for lower <= upper {
- message := this.ringBuffer[lower&RingBufferMask]
+ message := ringBuffer[lower&RingBufferMask]
if message != lower {
warning := fmt.Sprintf("\nRace condition--Sequence: %d, Message: %d\n", lower, message)
fmt.Printf(warning)
diff --git a/benchmark-disruptor/shared_writer_contended_write_test.go b/benchmark-disruptor/shared_writer_contended_write_test.go
index 08b6f70..4632366 100644
--- a/benchmark-disruptor/shared_writer_contended_write_test.go
+++ b/benchmark-disruptor/shared_writer_contended_write_test.go
@@ -3,18 +3,19 @@
import (
"runtime"
"testing"
+ "time"
"github.com/smartystreets/go-disruptor"
)
func BenchmarkSharedWriterReserveOneContendedWrite(b *testing.B) {
+ defer time.Sleep(DisruptorCleanup)
runtime.GOMAXPROCS(3)
- defer runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
- ringBuffer := [RingBufferSize]int64{}
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
BuildShared()
controller.Start()
defer controller.Stop()
@@ -44,10 +45,10 @@
}
func BenchmarkSharedWriterReserveManyContendedWrite(b *testing.B) {
+ defer time.Sleep(DisruptorCleanup)
runtime.GOMAXPROCS(3)
- defer runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
- ringBuffer := [RingBufferSize]int64{}
controller := disruptor.
Configure(RingBufferSize).
WithConsumerGroup(noopConsumer{}).
diff --git a/benchmark-disruptor/shared_writer_test.go b/benchmark-disruptor/shared_writer_test.go
index 2232478..c4616f5 100644
--- a/benchmark-disruptor/shared_writer_test.go
+++ b/benchmark-disruptor/shared_writer_test.go
@@ -1,16 +1,21 @@
package benchmarks
import (
+ "runtime"
"testing"
+ "time"
"github.com/smartystreets/go-disruptor"
)
func BenchmarkSharedWriterReserveOne(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
BuildShared()
controller.Start()
defer controller.Stop()
@@ -32,10 +37,13 @@
}
func BenchmarkSharedWriterReserveMany(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
BuildShared()
controller.Start()
defer controller.Stop()
diff --git a/benchmark-disruptor/writer_await_test.go b/benchmark-disruptor/writer_await_test.go
index 3a26e75..131c558 100644
--- a/benchmark-disruptor/writer_await_test.go
+++ b/benchmark-disruptor/writer_await_test.go
@@ -1,16 +1,21 @@
package benchmarks
import (
+ "runtime"
"testing"
+ "time"
"github.com/smartystreets/go-disruptor"
)
func BenchmarkWriterAwaitOne(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()
@@ -32,10 +37,13 @@
b.StopTimer()
}
func BenchmarkWriterAwaitMany(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()
diff --git a/benchmark-disruptor/writer_reservation_multiple_readers_test.go b/benchmark-disruptor/writer_reservation_multiple_readers_test.go
index bb52072..4527076 100644
--- a/benchmark-disruptor/writer_reservation_multiple_readers_test.go
+++ b/benchmark-disruptor/writer_reservation_multiple_readers_test.go
@@ -3,17 +3,19 @@
import (
"runtime"
"testing"
+ "time"
"github.com/smartystreets/go-disruptor"
)
func BenchmarkWriterReserveOneMultipleReaders(b *testing.B) {
+ defer time.Sleep(DisruptorCleanup)
runtime.GOMAXPROCS(3)
- defer runtime.GOMAXPROCS(2)
- ringBuffer := [RingBufferSize]int64{}
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}, SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}, SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()
@@ -35,12 +37,13 @@
}
func BenchmarkWriterReserveManyMultipleReaders(b *testing.B) {
+ defer time.Sleep(DisruptorCleanup)
runtime.GOMAXPROCS(3)
- defer runtime.GOMAXPROCS(2)
- ringBuffer := [RingBufferSize]int64{}
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}, SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}, SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()
diff --git a/benchmark-disruptor/writer_reservation_test.go b/benchmark-disruptor/writer_reservation_test.go
index 14719e6..2906019 100644
--- a/benchmark-disruptor/writer_reservation_test.go
+++ b/benchmark-disruptor/writer_reservation_test.go
@@ -1,16 +1,21 @@
package benchmarks
import (
+ "runtime"
"testing"
+ "time"
"github.com/smartystreets/go-disruptor"
)
func BenchmarkWriterReserveOne(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()
@@ -31,10 +36,13 @@
b.StopTimer()
}
func BenchmarkWriterReserveMany(b *testing.B) {
- ringBuffer := [RingBufferSize]int64{}
+ defer time.Sleep(DisruptorCleanup)
+ runtime.GOMAXPROCS(2)
+ defer runtime.GOMAXPROCS(1)
+
controller := disruptor.
Configure(RingBufferSize).
- WithConsumerGroup(SampleConsumer{&ringBuffer}).
+ WithConsumerGroup(SampleConsumer{}).
Build()
controller.Start()
defer controller.Stop()