Knative Serving allows for collecting runtime profiling data expected by the
pprof visualization tool. Profiling data is available for the autoscaler,
activator, controller, webhook and for the queue-proxy container which is
injected into the user application pod. When enabled Knative serves profiling
data on the default port 8008
through a web server.
Edit the config-observability
ConfigMap and add profiling.enable = "true"
:
kubectl edit configmap config-observability -n knative-serving
Use port-forwarding to get access to Knative Serving pods. For example, activator:
$ ACTIVATOR_POD=$(kubectl -n knative-serving get pods -l app=activator -o custom-columns=:metadata.name --no-headers)
$ kubectl port-forward -n knative-serving $ACTIVATOR_POD 8008:8008
View all available profiles at http://localhost:8008/debug/pprof/ through a web browser or request specific profiling data using one of the commands below:
go tool pprof http://localhost:8008/debug/pprof/heap
go tool pprof http://localhost:8008/debug/pprof/profile?seconds=30
go tool pprof http://localhost:8008/debug/pprof/block
wget http://localhost:8008/debug/pprof/trace\?seconds\=5 && go tool trace trace\?seconds\=5
go tool pprof http://localhost:8008/debug/pprof/allocs
go tool pprof http://localhost:8008/debug/pprof/mutex
go tool pprof http://localhost:8008/debug/pprof/goroutine
go tool pprof http://localhost:8008/debug/pprof/threadcreate
curl http://localhost:8008/debug/pprof/cmdline --output -
More information on profiling Go applications in this blog