Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How big is pprof import overhead in go

Tags:

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?

like image 323
RickyA Avatar asked Oct 24 '14 09:10

RickyA


People also ask

Does Pprof affect performance?

Profiling with pprof doesn't add much overhead, but being cheap doesn't mean it's free. A malicious actor can start sending a long running profiling query, affecting the overall application performance.

What is Pprof?

pprof is a tool for visualization and analysis of profiling data. pprof reads a collection of profiling samples in profile. proto format and generates reports to visualize and help analyze the data. It can generate both text and graphical reports (through the use of the dot visualization package).

What is profiling in Go?

Profiling: Profiling tools analyze the complexity and costs of a Go program such as its memory usage and frequently called functions to identify the expensive sections of a Go program. Tracing: Tracing is a way to instrument code to analyze latency throughout the lifecycle of a call or user request.

How can you view the Profiler output in CPU Pprof in the browser?

Instead it's a trace and you can view it using go tool trace (not go tool pprof ). You can see the available profiles with http://localhost:6060/debug/pprof/ in your browser.


1 Answers

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.

like image 122
Didier Spezia Avatar answered Oct 22 '22 23:10

Didier Spezia