183 Contention and Concurrency Tuning

183 Contention and Concurrency Tuning

Throughput often degrades due to contention long before CPU saturation reaches 100%.

Contention Shape

goroutines -> shared lock/resource -> queueing -> latency growth -> throughput collapse

Diagnostic Approach

  • Identify shared-state hotspots.
  • Measure mutex/block profiles.
  • Correlate lock wait with p95/p99 latency.

Tuning Strategy

  • Reduce shared mutable state.
  • Partition state (sharding) where appropriate.
  • Bound fan-out and queue sizes.

Performance work is complete only when improvements are verified under realistic load.