Profiling Code II

Profiling an HTTP server

As discussed, the net/http/pprof package should be used when we want to collect profiling data for a Go application that runs an HTTP server. To that end, importing net/http/pprof installs various handlers under the /debug/pprof/ path. We are going to see more on this in a short while. For now, it is enough to remember that the net/http/pprof package should be used to profile web applications, whereas runtime/pprof should be used to profile all other kinds of applications.

Coding example

The technique is illustrated in profileHTTP.go, which comes with the following code:

Get hands-on with 1200+ tech skills courses.