How to do one-off profiling for dogfood and production using pprof
Go has built-in support for a sampling profiler
pprof,which can be used to investigate CPU usage, heap usage and more.
You can obtain and examine a profile from a running Sourcegraph instance as follows:
- Select the right Kubernetes context using
- Set up port-forwarding for the pod you're interested in profiling using
kubectl. For example:
kubectl port-forward precise-code-intel-worker-0000000000-00000 6061:6060This will map port 6060 on the pod to port 6061 on your machine.
- Record a profile.
# Sample CPU usage for 60 seconds go tool pprof -seconds 60 http://localhost:6061/debug/pprof/profile # Sample heap usage for 60 seconds go tool pprof -seconds 60 http://localhost:6061/debug/pprof/heapThis will save the output to a temporary file. (Or you can specify a path using
- Examine the generated using
go tool pprof:
# in the web UI go tool pprof -http :9999 /path/to/profile.pb.gz # in a REPL go tool pprof /path/to/profile.pb.gzThe web UI supports visualizing the output as a flamegraph, as a call graph with weighted edges, and more.