forked from smarty-prototypes/go-disruptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oliver, Jonathan
committed
May 19, 2014
1 parent
279cc74
commit 873ee95
Showing
9 changed files
with
76 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/smartystreets/go-disruptor" | ||
) | ||
|
||
const Mod = 1000000 * 10 // 1 million * N | ||
|
||
func consume(writerBarrier disruptor.Barrier, writerCursor, readerCursor *disruptor.Cursor) { | ||
reader := disruptor.NewReader(writerBarrier, writerCursor, readerCursor) | ||
started := time.Now() | ||
|
||
for { | ||
sequence, remaining := reader.Receive() | ||
if remaining == disruptor.Idle { | ||
} else if remaining == disruptor.Gating { | ||
} else { | ||
for ; remaining >= 0; remaining-- { | ||
sequence++ | ||
|
||
if sequence%Mod == 0 { | ||
finished := time.Now() | ||
fmt.Println(sequence, finished.Sub(started)) | ||
started = time.Now() | ||
} | ||
|
||
if sequence != ringBuffer[sequence&RingMask] { | ||
message := ringBuffer[sequence&RingMask] | ||
panic(fmt.Sprintf("Sequence: %d, Message %d\n", sequence, message)) | ||
} | ||
|
||
} | ||
|
||
reader.Commit(sequence) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import "github.com/smartystreets/go-disruptor" | ||
|
||
func publish(writer *disruptor.Writer) { | ||
for { | ||
_, upper := writer.Reserve(1) | ||
if upper == disruptor.Gating { | ||
continue | ||
} | ||
|
||
// ringBuffer[(upper-2)&RingMask] = upper - 2 | ||
// ringBuffer[(upper-1)&RingMask] = upper - 1 | ||
ringBuffer[upper&RingMask] = upper | ||
|
||
writer.Commit(upper) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package disruptor | ||
|
||
func (this *Reader) Commit(sequence int64) { | ||
this.readerCursor.value = sequence | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters