Optimize Go applications using the built-in pprof package for CPU, memory, and goroutine profiling to identify bottlenecks and improve performance.
pprof
package for memory and CPU profiling. This section provides guidance on setting up and retrieving profiles using pprof
. These profiles are valuable for troubleshooting issues and can sometimes be the only way to gain meaningful context.
pprof
endpoints, start the router with the following environment variable:
pprof
HTTP server will be accessible at http://localhost:6060
. Exposing this endpoint to production environments is highly discouraged due to security risks./debug/pprof/heap
— Memory profile.
/debug/pprof/profile
— CPU profile.
/debug/pprof/goroutine
— Goroutine profile.
/debug/pprof/threadcreate
— Thread creation profile.
/debug/pprof/block
— Block profile.
go tool pprof
interactive commands such as top
, list
, peek
, and web
.