25

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 Answer 1

36

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.

4
  • 1
    I have add that WHEN the CPU sampling is enabled, it is heavy. As in "will drop the performance of your application to 1% from the original" heavy. I would be myself squeamish of leaving a possibility of accidental activation around.
    – user918176
    Commented Oct 24, 2014 at 15:18
  • 5
    @user918176: Nonsense. Commented Aug 2, 2015 at 20:26
  • thanks @Didier for the info. Regarding So compiling with this package should not impact much the performance of the application, do you find any official doc on what could be the performance hit? Commented Jun 19, 2020 at 17:25
  • According to this article, even profiling CPU 10 seconds every minute will lead to around 5% overhead max.
    – rustyx
    Commented Jun 5, 2021 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.