Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
title: Profiling Karmada
title: Karmada 性能分析
---

## Enable profiling
## 启用性能分析

To profile Karmada components running inside a Kubernetes pod, set --enable-pprof flag to true in the yaml of Karmada components.
The default profiling address is 127.0.0.1:6060, and it can be configured via `--profiling-bind-address`.
The components which are compiled by the Karmada source code support the flag above, including `Karmada-agent`, `Karmada-aggregated-apiserver`, `Karmada-controller-manager`, `Karmada-descheduler`, `Karmada-search`, `Karmada-scheduler`, `Karmada-scheduler-estimator`, `Karmada-webhook`.

```
--enable-pprof
Enable profiling via web interface host:port/debug/pprof/.
--profiling-bind-address string
The TCP address for serving profiling(e.g. 127.0.0.1:6060, :6060). This is only applicable if profiling is enabled. (default ":6060")
若要对运行在 Kubernetes Pod 中的 Karmada 组件进行性能分析,需要在组件的 YAML 配置中将 `--enable-pprof` 参数设置为 `true`。
默认的分析地址为 `127.0.0.1:6060`,也可以通过 `--profiling-bind-address` 参数进行配置。

以下由 Karmada 源码构建的组件支持该功能:`Karmada-agent`, `Karmada-aggregated-apiserver`, `Karmada-controller-manager`, `Karmada-descheduler`, `Karmada-search`, `Karmada-scheduler`, `Karmada-scheduler-estimator`, `Karmada-webhook`.

```
--enable-pprof
通过 Web 接口 host:port/debug/pprof/ 启用性能分析。
--profiling-bind-address string
用于提供性能分析服务的 TCP 地址(如 127.0.0.1:6060、:6060)。仅在启用分析时有效,默认值为 ":6060"。
```

## Expose the endpoint at the local port
## 通过本地端口暴露分析接口

You can get at the application in the pod by port forwarding with kubectl, for example:
你可以通过 `kubectl port-forward` 命令将 Pod 中的分析端口转发到本地,例如:

```shell
$ kubectl -n karmada-system get pod
Expand All @@ -33,31 +34,35 @@ Forwarding from 127.0.0.1:6060 -> 6060
Forwarding from [::1]:6060 -> 6060
```

The HTTP endpoint will now be available as a local port.
此时,HTTP 分析接口将可通过本地端口访问。


## Generate the data
## 生成分析数据

You can then generate the file for the memory profile with curl and pipe the data to a file:
你可以通过 `curl` 命令获取内存分析数据(heap profile)并保存到文件:

```shell
curl http://localhost:6060/debug/pprof/heap > heap.pprof
curl http://localhost:6060/debug/pprof/heap > heap.pprof
```

Generate the file for the CPU profile with curl and pipe the data to a file (7200 seconds is two hours):
获取 CPU 分析数据并保存(以下示例持续时间为 7200 秒,即两小时):

```shell
curl "http://localhost:6060/debug/pprof/profile?seconds=7200" > cpu.pprof
```

## Analyze the data

To analyze the data:
## 分析数据

使用 Go 的 `pprof` 工具分析生成的数据文件:

```shell

go tool pprof heap.pprof
```

## Read more about profiling

1. [Profiling Golang Programs on Kubernetes](https://danlimerick.wordpress.com/2017/01/24/profiling-golang-programs-on-kubernetes/)
2. [Official Go blog](https://blog.golang.org/pprof)
## 深入阅读性能分析相关内容

1. [在 Kubernetes 上分析 Golang 程序性能](https://danlimerick.wordpress.com/2017/01/24/profiling-golang-programs-on-kubernetes/)
2. [Go 官方博客](https://blog.golang.org/pprof)