64 goroutines on four cores: Mutex is 1.40 times faster than a one-way channel, but its p99 is four times higher
When G goroutines on P cores hammer the same shared counter, how many operations a second do sync.Mutex, an owner-goroutine channel and a buffered channel manage, and how do tail latency and fairness of waiting change?
Finding
With 64 goroutines on four cores, sync.Mutex is 1.40 times faster than a one-way channel (10.46 and 7.47 million operations/s) but its p99 wait is 4.00 times higher (294,911 and 73,727 ns). On eight cores the Mutex ranges from 16.27 to 26.25 million operations/s across the two runs (a bimodal cell); the one-way channel holds at 7.31 and 7.32 million. More than half of the cells are flagged in both runs; confidence is low.
measured 4 days ago