ZenQ

A thread-safe queue faster and more resource efficient than golang's native channels

MIT License

Stars
656
ZenQ - Drop-in replacement for channels

Published by alphadose over 2 years ago

By changing the spinning lastCommittedIndex to slot based CAS operations, we gain a lot of performance as compared to channels for the following tested cases:-

  1. Single Producer Single Consumer (gain of around 94 seconds with input size 6 * 108)
  2. Multi Producer Single Consumer where NUM_WRITER_GOROUTINES < NUM_CPU_CORES
  3. Multi Producer Single Consumer where NUM_WRITER_GOROUTINES > NUM_CPU_CORES as illustrated below
Benchmark_Chan_NumWriters1000_InputSize7000000-8    1  1984590667 ns/op  497344 B/op   1817 allocs/op
Benchmark_ZenQ_NumWriters1000_InputSize7000000-8    2   777197480 ns/op    8736 B/op     21 allocs/op