-
Notifications
You must be signed in to change notification settings - Fork 1.6k
📖 Add new documentation explaining the usage of Pprof #4160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Monitoring Performance with Pprof | ||
|
|
||
| [Pprof][github], a Go profiling tool, helps identify performance bottlenecks in areas like CPU and memory usage. It's integrated with the controller-runtime library's HTTP server, enabling profiling via HTTP endpoints. You can visualize the data using go tool pprof. Since [Pprof][github] is built into controller-runtime, no separate installation is needed. [Manager options][manager-options-doc] make it easy to enable pprof and gather runtime metrics to optimize controller performance. | ||
|
|
||
| <aside class="note warning"> | ||
| <h1>Not Recommended for Production</h1> | ||
|
|
||
| While [Pprof][github] is an excellent tool for profiling and debugging, it is not recommended to leave it enabled in production environments. The primary reasons are: | ||
|
|
||
| 1. **Security Risk**: The profiling endpoints expose detailed information about your application's performance and resource usage, which could be exploited if accessed by unauthorized users. | ||
| 2. **Overhead**: Running profiling can introduce performance overhead, mainly CPU usage, especially under heavy load, potentially impacting production workloads. | ||
|
|
||
| </aside> | ||
|
|
||
| ## How to use Pprof? | ||
|
|
||
| 1. **Enabling Pprof** | ||
|
|
||
| In your `cmd/main.go` file, add the field: | ||
|
|
||
| ```golang | ||
| mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
| ... | ||
| // PprofBindAddress is the TCP address that the controller should bind to | ||
| // for serving pprof. Specify the manager address and the port that should be bind. | ||
| PprofBindAddress: ":8082", | ||
| ... | ||
| }) | ||
| ``` | ||
|
|
||
| 2. **Test It Out** | ||
|
|
||
| After enabling [Pprof][github], you need to build and deploy your controller to test it out. Follow the steps in the [Quick Start guide][quick-start-run-it] to run your project locally or on a cluster. | ||
|
|
||
| Then, you can apply your CRs/samples in order to monitor the performance of its controllers. | ||
|
|
||
| 3. **Exporting the data** | ||
|
|
||
| Using `curl`, export the profiling statistics to a file like this: | ||
|
|
||
| ```bash | ||
| # Note that we are using the bind host and port configured via the | ||
| # Manager Options in the cmd/main.go | ||
| curl -s "http://127.0.0.1:8082/debug/pprof/profile" > ./cpu-profile.out | ||
| ``` | ||
|
|
||
| 4. **Visualizing the results on Browser** | ||
|
|
||
| ```bash | ||
| # Go tool will open a session on port 8080. | ||
| # You can change this as per your own need. | ||
| go tool pprof -http=:8080 ./cpu-profile.out | ||
| ``` | ||
|
|
||
| Visualizaion results will vary depending on the deployed workload, and the Controller's behavior. | ||
| However, you'll see the result on your browser similar to this one: | ||
|
|
||
|  | ||
|
|
||
| [manager-options-doc]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager | ||
| [quick-start-run-it]: ../quick-start.md#test-it-out | ||
| [github]: https://github.com/google/pprof | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.