500ms per 100 million operations (200million/second) with a lot of jitter.
diff --git a/example/consumer.go b/example/consumer.go
index ba02982..ae78abf 100644
--- a/example/consumer.go
+++ b/example/consumer.go
@@ -1,9 +1,13 @@
package main
-import "bitbucket.org/jonathanoliver/go-disruptor"
+import (
+ "time"
+
+ "bitbucket.org/jonathanoliver/go-disruptor"
+)
func consume(barrier disruptor.Barrier, source, sequence *disruptor.Sequence) {
- worker := disruptor.NewWorker(barrier, ConsumerHandler{}, source, sequence)
+ worker := disruptor.NewWorker(barrier, &ConsumerHandler{time.Now()}, source, sequence)
for {
worker.Process()
diff --git a/example/consumer_handler.go b/example/consumer_handler.go
index 77b95a3..116bb96 100644
--- a/example/consumer_handler.go
+++ b/example/consumer_handler.go
@@ -1,10 +1,18 @@
package main
-type ConsumerHandler struct{}
+import (
+ "fmt"
+ "time"
+)
-func (this ConsumerHandler) Consume(sequence, remaining int64) {
- message := ringBuffer[sequence&RingMask]
- if message != sequence {
+type ConsumerHandler struct{ started time.Time }
+
+func (this *ConsumerHandler) Consume(sequence, remaining int64) {
+ if sequence%Mod == 0 {
+ finished := time.Now()
+ fmt.Println(sequence, finished.Sub(this.started))
+ this.started = time.Now()
+ } else if sequence != ringBuffer[sequence&RingMask] {
panic("Race condition")
}
}
diff --git a/example/publisher.go b/example/publisher.go
index b0c85c2..77f2fe0 100644
--- a/example/publisher.go
+++ b/example/publisher.go
@@ -1,24 +1,12 @@
package main
-import (
- "fmt"
- "time"
-
- "bitbucket.org/jonathanoliver/go-disruptor"
-)
+import "bitbucket.org/jonathanoliver/go-disruptor"
func publish(sequencer *disruptor.SingleProducerSequencer) {
- started := time.Now()
for sequence := int64(0); sequence < MaxIterations; sequence++ {
sequencer.Next(1)
ringBuffer[sequence&RingMask] = sequence
sequencer.Publish(sequence)
- if sequence%Mod == 0 && sequence > 0 {
- finished := time.Now()
- elapsed := finished.Sub(started)
- fmt.Println(sequence, elapsed)
- started = time.Now()
- }
}
}