Completed TODO of keeping cursors close together during wireup.
diff --git a/disruptor.go b/disruptor.go
index df1f104..d659f4d 100644
--- a/disruptor.go
+++ b/disruptor.go
@@ -6,8 +6,6 @@
}
func NewDisruptor(builder Builder) Disruptor {
- // TODO: Cursors should probably all be created at the same time in wireup to keep them as close together as possible:
- // https://news.ycombinator.com/item?id=7800825
return Disruptor{}
}
diff --git a/wireup.go b/wireup.go
index 83a88b7..71dfc96 100644
--- a/wireup.go
+++ b/wireup.go
@@ -1,9 +1,12 @@
package disruptor
+// Cursors should be a party of the same backing array to keep them as close together as possible:
+// https://news.ycombinator.com/item?id=7800825
type (
Wireup struct {
capacity int64
groups [][]Consumer
+ cursors []*Cursor // backing array keeps cursors (with padding) in contiguous memory
}
)
@@ -11,6 +14,7 @@
this := Wireup{
capacity: capacity,
groups: [][]Consumer{},
+ cursors: []*Cursor{NewCursor()},
}
return this.WithConsumerGroup(consumers...)
@@ -24,6 +28,10 @@
target := make([]Consumer, len(consumers))
copy(target, consumers)
+ for i := 0; i < len(consumers); i++ {
+ this.cursors = append(this.cursors, NewCursor())
+ }
+
this.groups = append(this.groups, target)
return this
}