minio / sidekick

High Performance HTTP Sidecar Load Balancer
GNU Affero General Public License v3.0
546 stars 82 forks source link

Enable live pprof at /.pprof/ #71

Closed vadmeste closed 1 year ago

vadmeste commented 1 year ago

Running go tool pprof http://localhost:8080/minio/pprof/profile?seconds=30 will get CPU profiling for 20 seconds

Supported profilers are: goroutine, threadcreate, heap, allocs, block, mutex, symbol, trace and profile (cpu profiling)

klauspost commented 1 year ago

@vadmeste I find the HTTP profilers to be much more useful since it doesn't require restarting. Maybe we could expose them on a separate port, so adding a parameter --pprof=":6060" would expose profiling on a separate port.

There is also a standard HTTP interface to profiling data. In an HTTP server, adding import _ "net/http/pprof" will install handlers for a few URLs under /debug/pprof/. Then you can run go tool pprof with a single argument—the URL to your server’s profiling data and it will download and examine a live profile.

go tool pprof http://localhost:6060/debug/pprof/profile   # 30-second CPU profile
go tool pprof http://localhost:6060/debug/pprof/heap      # heap profile
go tool pprof http://localhost:6060/debug/pprof/block     # goroutine blocking profile
harshavardhana commented 1 year ago

@vadmeste I find the HTTP profilers to be much more useful since it doesn't require restarting. Maybe we could expose them on a separate port, so adding a parameter --pprof=":6060" would expose profiling on a separate port.

There is also a standard HTTP interface to profiling data. In an HTTP server, adding import _ "net/http/pprof" will install handlers for a few URLs under /debug/pprof/. Then you can run go tool pprof with a single argument—the URL to your server’s profiling data and it will download and examine a live profile.

go tool pprof http://localhost:6060/debug/pprof/profile   # 30-second CPU profile
go tool pprof http://localhost:6060/debug/pprof/heap      # heap profile
go tool pprof http://localhost:6060/debug/pprof/block     # goroutine blocking profile
  • You will need to add the pprof to a custom mux, but there are easy functions for that. I can send a PR if you'd like.

This is better as @klauspost suggested

vadmeste commented 1 year ago

@klauspost I made the change, by the way, this does not require any flag.. it can be always enabled

klauspost commented 1 year ago

@vadmeste The reason for the separate port is for safety reasons. While adding it to the default port is a lot easier, both for use and setup it does allow anyone to access potentially resource intensive calls.

vadmeste commented 1 year ago

@vadmeste The reason for the separate port is for safety reasons. While adding it to the default port is a lot easier, both for use and setup it does allow anyone to access potentially resource intensive calls.

But this will require a flag and a restart

klauspost commented 1 year ago

Yes, why I wrote that "adding it to the default port is a lot easier, both for use and setup". But it doesn't look like something we would like to have exposed externally.

But it is easier to block a port.