11## Sequence
2- Sequence is the fundemtal data strcture for the entire package.
2+ Sequence is the fundamental data structure for the entire package.
33
4- In short, sequence is just a thread-safe counter, which for the consumer and producer to wait, get then process
5- a slot from the ring buffer. Refer to Sequencer for more details.
4+ In short, sequence is just a thread-safe counter, points to a slot in the ring buffer.
5+ The consumer and producer uses a wait strategy to wait for the number.
6+ Once get the slot, then the consumer or producer can continue its process.
67
78Following Sequences are tested
89* struct with int64
@@ -13,22 +14,26 @@ All performance testing are done in Windows 10 with i5-11400F @ 2.60GHz in conso
1314``` powershell
1415#bechmark
1516go test -benchmem -run=^$ -tags -race -bench ^BenchmarkSequenceGet$ goDisruptor/internal
17+
1618#profile
1719go test -cpuprofile cpu.prof -memprofile mem.prof -benchmem -run=^$ -tags -race -bench ^BenchmarkSequenceGet$ goDisruptor/internal
20+
1821#get top function calls
1922go tool pprof cpu.prof => top
23+
2024# generate call graph
2125go tool pprof cpu.prof => png
26+
2227# get top memory allocation
2328go tool pprof mem.prof => top
2429```
2530
2631### Performance results
27- || Get without GC| Get with GC| Set without GC| Set with GC| Concurrent Get and Set without GC
28- | -- | -- | -- | -- | -- | -- |
29- | struct int64| 10.18 ns/op| 11.42 ns/op| 4.624 ns/op| 4.615 ns/op| 21.70 ns/op|
30- | struct [ 8] int64| 23.10 ns/op| 36.69 ns/op| 4.714 ns/op| 5.033 ns/op| 49.09 ns/op|
31- | int64| 0.2708 ns/op| 0.2416 ns/op| 4.936 ns/op| 5.150 ns/op| 5.291 ns/op|
32+ | | Get without GC | Get with GC | Set without GC | Set with GC | Concurrent Get and Set without GC |
33+ | ----------------- | ---------------- | -------------- | ---------------- | ------------- | ----------------------------------- |
34+ | struct int64 | 10.18 ns/op | 11.42 ns/op | 4.624 ns/op | 4.615 ns/op | 21.70 ns/op |
35+ | struct [ 8] int64 | 23.10 ns/op | 36.69 ns/op | 4.714 ns/op | 5.033 ns/op | 49.09 ns/op |
36+ | int64 | 0.2708 ns/op | 0.2416 ns/op | 4.936 ns/op | 5.150 ns/op | 5.291 ns/op |
3237
3338
3439### Get vs. Set
@@ -38,8 +43,8 @@ go tool pprof mem.prof => top
3843// no significant difference in call graph, likely due to the I/O, lock, Timer, scheduling etc.
3944
4045### Impact of malloc
41- ** mallocgc allocates 8 bytes cost around 8ns, compare to 20ns for 64 bytes
42- ** atomic.StoreInt64 doesn't call mallocgc , it is consistent 4ns
46+ ** malloc allocates 8 bytes cost around 8ns, compare to 20ns for 64 bytes
47+ ** atomic.StoreInt64 doesn't call malloc , it is consistent 4ns
4348** implementation using int64 directly, no allocation to heap, 0.2 ns only
4449
4550### Impact of the struct
0 commit comments