Posts

Showing posts with the label Golang

Quickly Setup Golang pprof and debugging for Memory Leak

Image
This post gives you quick steps for debugging memory leak using pprof in Go lang microservices built with Gorilla Mux: Setting up pprof in Go lang Running and viewing the memory profile Pinpointing the code culprit line Setting up pprof in Go lang First, you have to include pprof package in your Go file. Go file is the place where you declare your routes: import ( "encoding/json" "errors" "fmt" "net/http" _ "net/http/pprof" "github.com/gorilla/mux" ) Then you need to add a path prefix 'debug'. PathPrefix registers a new route with a matcher for the URL path prefix. We do this to see the memory profiler on the browser. router := mux.NewRouter() router.PathPrefix("/debug/").Handler(http.DefaultServeMux) router.Path("/healthCheck").Methods("GET").HandlerFunc(s.HealthCheck) Do not be confused since pprof package not being used anywhe...