Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
1 / 5
0

atomic.Pointer[T] for Lock-Free Cache Updates That Don't Race

DEV Community·Gabriel Anhaia·25 days ago
#v4l9fzXH
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub A team I talked to had a feature-flag cache. A small map of flag-name to bool, refreshed from a config service every 30 seconds. Every HTTP handler in their service read from it on the way in. The first version used sync.RWMutex because that is what every Go intro reaches for when you say "read-heavy". Under load testing the read path looked fine. Under real traffic (tens of thousands of req/s across dozens of cores) the p99 climbed. A flame graph put runtime.semacquire and sync.(*RWMutex).RLock on the hot path. The mutex was not contended in the way people usually mean. It was paying cache-line traffic on every reader because every RLock writes the reader-count field.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More