How big is pprof import overhead in go

I have a couple of go programs that have a unused inport of net/http/pprof in them.

import _ "net/http/pprof"
...
//http.ListenAndServe("127.0.0.1:6060", nil)

I was wondering what the overhead of this import is in term of CPU and Mem. Aka. Should I remove then in prod (yes), but what would be the impact if I forgot?

Related: what are the exact sideeffects of this import? It registers some http handlers, but does it also inject things in go’s malloc functions?

1 Like

The overhead of importing the net/http/pprof package is pretty limited: it just installs some handlers for the http server. See the source code at:

http://golang.org/src/pkg/net/http/pprof/pprof.go

CPU profiling is not activated at initialization time, it is only activated for a period of time (30 seconds by default) when the /debug/pprof/profile REST service is called. So compiling with this package should not impact much the performance of the application (except that extra goroutines for the http server are needed).

Now, during the execution of /debug/pprof/profile, CPU sampling is activated, so a performance overhead is expected. I guess it can be used for production code provided the access to the corresponding port is restricted to the administrators of the application.

Refer: stackoverflow