Problem Statement
Your high-frequency trading system written in Go has latency spikes every few seconds. Using GODEBUG, you discover GC pauses are the culprit. Explain Go's garbage collector and how to tune it for low-latency applications.
Tri-Color Mark and Sweep Algorithm
Go uses a concurrent, tri-color, mark-and-sweep garbage collector:
- White: Not yet scanned (candidates for collection)
- Grey: Scanned, but children not scanned
- Black: Scanned, and all children scanned (reachable)
GC Phases
Debugging GC with GODEBUG
Tuning GC for Low Latency
Reducing GC Pressure
The Ballast Technique (Legacy)
Follow-up Questions
- Is Go's GC generational? Compacting?
- What is a write barrier and why is it needed?
- How does sync.Pool interact with GC cycles?