Tackling Contention : The Monster in sync.Locker
summary
Measures show mutex wait time dominating CPU profiles: pprof reports tiny flat time but large cumulative time spent acquiring locks when many goroutines increment a shared counter. Live trace captures in production (minutes at a time) reveal tail latency and scheduler delays. Cache experiments show 64-bit writes beat 8-bit due to cache-line invalidation, so false sharing is real. Remedies: split state into buckets carefully, pad structs or use sync.Map or an atomic CAS loop for read-mostly values, but atomics break the race detector and cost complexity.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 0:46What is contention
- 1:38Tools
- 2:44Example
- 3:45Output
- 4:20Supersize
- 5:10Trace
- 5:36Regions
- 6:55Routines
- 7:14Trace view
- 7:56Measuring too much
- 8:12Dont measure too much
- 8:28Maybe before
- 9:08Hardware
- 9:39Stop sharing
- 10:06Content less
- 10:26Mutex
- 11:03Rainbows
- 12:13Synchronization
- 12:46Read Mutex
- 13:18SyncMap
- 14:08Raw
- 15:05Clock
- 16:20Performance
- 17:05Padding
- 18:20Unsafe
- 21:47Questions








