Go Runtime Tuning and Profiling
Go is famous for working out of the box. At scale, knowing where the levers are pays back.
Why Go default works
Go runtime: garbage collector tuned for sub-ms pause; goroutine scheduler scales to many cores.
Defaults work for 95% of workloads.
Four runtime parameters
- GOMAXPROCS, CPU count override.
- GOGC, GC trigger frequency.
- GOMEMLIMIT, soft memory limit (1.19+).
- GODEBUG, runtime tracing flags.
pprof workflow
go tool pprof for CPU and heap profiles.
Workflow: capture; analyze; identify hot path; fix; verify.
Production profiling
Continuous profiler in production: Pyroscope, Polar Signals. Low overhead; always-on.
Replaces ‘capture profile during incident’ with ‘trends over weeks.’
Antipatterns
- GOMAXPROCS not set in containers. Go sees host CPU count; thrashing.
- No production profiling. Diagnose blind.
- GC tuning by guess. Defaults are usually right.
What to do this week
Three moves. (1) Apply this pattern to your slowest production endpoint. (2) Measure p99 before/after. (3) Document the win and ship the runbook so the team can reproduce.