Skip to content

Performance monitoring

Go performance monitoring

Go services are fast by default, so problems tend to be leaks and contention: goroutines that never exit, allocations that drive the GC and locks under load.

2 min read8 sectionsUpdated

On this page

Go runtime metrics

MetricSourceWorry when
Goroutinesruntime.NumGoroutineRises steadily and never falls
Heap in use / allocation rateruntime/metricsAllocation rate high on hot paths
GC pause and CPU fractionruntime/metricsGC using a noticeable share of CPU
Open file descriptorsProcess metricsNear the limit; see too many open files
Handler p95 and error rateTracesAbove target

Profiling with pprof

go
import _ "net/http/pprof" // registers /debug/pprof handlers

go func() {
	// bind to localhost only; never expose pprof publicly
	log.Println(http.ListenAndServe("127.0.0.1:6060", nil))
}()
bash
go tool pprof -http=:8081 http://127.0.0.1:6060/debug/pprof/profile?seconds=30   # CPU
go tool pprof -http=:8081 http://127.0.0.1:6060/debug/pprof/heap                  # memory
curl -s http://127.0.0.1:6060/debug/pprof/goroutine?debug=2 | head -n 60           # stuck goroutines

Typical Go bottlenecks

  • Goroutine leaks: goroutines blocked forever on a channel or a request without a timeout.
  • Missing timeouts: http.Client{} has no timeout by default; set one, and pass contexts with deadlines.
  • Lock contention on a shared map; use sharding, sync.Map for read-heavy cases, or fewer shared structures.
  • Allocation-heavy JSON on hot paths; reuse buffers, avoid reflection-heavy encoding where it matters.
  • database/sql pool limits (SetMaxOpenConns) too low, so queries queue.

Tracing

Wrap handlers with otelhttp.NewHandler, clients with otelhttp.NewTransport, and pass ctx everywhere. The full setup, with the tracer provider and exporter, is in OpenTelemetry for Go.

Frequently asked questions

Is it safe to run pprof in production?

Yes, if it is only reachable internally. CPU profiles add some overhead while recording; heap and goroutine snapshots are cheap.

How do I find a goroutine leak?

Compare goroutine profiles taken minutes apart. Stacks whose count keeps growing point to the code that starts goroutines that never finish.

Check it now, free

  • Goroutine leaks in Go: how to find and fix them: Find and fix goroutine leaks in Go: read pprof goroutine profiles, spot blocked channels and missing context cancellation, and use goleak in your tests.
  • OpenTelemetry for Flask: Instrument a Flask app with OpenTelemetry, in code or with zero code: trace routes, SQLAlchemy and outgoing calls, and export to VitalRix.
  • PHP performance monitoring: Monitor PHP and Laravel apps: request latency, PHP-FPM worker saturation, OPcache hit rate, slow queries, external calls and errors.
  • Python performance monitoring: Monitor Python web apps: request latency per route, worker saturation, the GIL and CPU-bound code, database time, Celery queues and memory.
  • Ruby and Rails performance monitoring: Monitor Ruby on Rails apps: request latency per action, Puma thread and worker saturation, ActiveRecord queries, Sidekiq queues, memory bloat and GC.
  • OpenTelemetry for Django: Trace a Django app with OpenTelemetry: auto-instrument views and the ORM, run under gunicorn safely, trace Celery tasks and export to VitalRix.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.