-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the generation of pprof profiles of heap usage by using jemalloc facilities. Signed-off-by: Flavio Castelli <[email protected]>
- Loading branch information
Showing
7 changed files
with
199 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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,56 @@ | ||
# Profiling | ||
|
||
Ensure the `policy-server` is running with the `--enable-pprof` flag. This can also be set with the `KUBEWARDEN_ENABLE_PPROF=1` environment variable. | ||
|
||
## CPU | ||
|
||
1. Port-forward policy-server port (8443): | ||
|
||
```sh | ||
kubectl port-forward -n kubewarden service/policy-server-default 8443:8443 | ||
``` | ||
|
||
1. Download the CPU profile using `curl`: | ||
|
||
```sh | ||
curl --insecure https://localhost:8443/debug/pprof/cpu -o cpu_profile.prof | ||
``` | ||
|
||
1. Use [`pprof`](https://github.com/google/pprof) to analyze the profile: | ||
|
||
```sh | ||
pprof -http=:8080 cpu_profile.prof | ||
``` | ||
|
||
## Memory | ||
|
||
By default memory profiling is not active. This gets automatically activated when the first | ||
request is sent to the `/debug/pprof/heap` endpoint. | ||
|
||
When the memory profiling is active, the CPU usage of the Policy Server will increase. | ||
Finally, once the memory profiling is activated, there's no way to deactivate it. | ||
|
||
Note: the memory profile requires some sampling, since we start with the memory profiling disabled, | ||
the first memory profile will be empty. The second one will contain the memory usage of the Policy Server. | ||
|
||
To obtain a memory profile: | ||
|
||
1. Port-forward policy-server port (8443): | ||
|
||
```sh | ||
kubectl port-forward -n kubewarden service/policy-server-default 8443:8443 | ||
``` | ||
|
||
1. Download the CPU profile using `curl`: | ||
|
||
```sh | ||
curl --insecure https://localhost:8443/debug/pprof/heap -o heap_profile.prof | ||
``` | ||
|
||
1. Use [`pprof`](https://github.com/google/pprof) to analyze the profile: | ||
|
||
```sh | ||
pprof -http=:8080 heap_profile.prof | ||
``` | ||
|
||
**Warning:** do not use the `pprof` tool from the `go tool` binary, it cannot handle the memory profile generated by Policy Server. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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