I just found this library that provides a non-locking ring that works faster than channels: https://github.com/textnode/gringo (and it works very fast, especially with GOMAXPROCS> 1)
But the interesting part is the structure for managing queue status:
type Gringo struct { padding1 [8]uint64 lastCommittedIndex uint64 padding2 [8]uint64 nextFreeIndex uint64 padding3 [8]uint64 readerIndex uint64 padding4 [8]uint64 contents [queueSize]Payload padding5 [8]uint64 }
If I delete the paddingX [8] uint64 fields, it runs about 20% slower. How can it be?
Also appreciate if someone explained why this blocking algorithm is much faster than channels, even buffered ones?
concurrency parallel-processing go
Leonid Bugaev
source share