本页面使用机器翻译自英语,可能包含错 误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)
轮廓节点数据
剖析是了解和优化 Kaia 节点性能的重要工具。 本教程将指导您利用 Kaia 的调试 API 和 net/http/pprof Go 软件包,学习 Kaia 节点操作员可用的各种剖析技术。
先决条件
在开始之前,请确保
-
节点设置: 您的 Kaia 节点已正确安装并运行。
-
** 访问节点控制台:** 您需要通过 节点控制台 与节点交互。
-
工具: 在系统中安装 Go,以便使用
go tool pprof和go tool trace。 您可以通过运行
go version
1. 管理剖析:如何启动、停止和检查状态
Kaia 节点提供了一个 "debug "API,可提供多种剖析方法。 您可以通过节点控制台或JSON-RPC API 调用 与这些方法交互。
1.1 启动 pprof HTTP 服务器
pprof HTTP 服务器可让您高效地收集和分析剖析数据。
# Start pprof server with default settings (localhost:6060)> debug.startPProf()# Start pprof server on a specific address and port> debug.startPProf("localhost", 8080)
访问 pprof 端点
pprof 服务器运行后,可通过以下网址访问剖析数据:
- http://localhost:6060/debug/pprof/ - 可用配置文件概览。
- http://localhost:6060/memsize/ - 内存大小报告。
- http://localhost:6060/debug/vars - Prometheus 指标的导出程序。
1.2 停止 pprof HTTP 服务器
> debug.stopPProf()
1.3 检查 pprof 是否正在运行
> debug.isPProfRunning()true # if runningfalse # if not running
2. 收集简介
pprof 服务器运行后,您可以使用多种方法收集各种配置文件,以分析节点的性能。
2.1 使用网络界面收集
在网络浏览器中输入相应的端点,以收集不同的配置文件,如以下示例所示:
收集堆配置文件
http://localhost:6060/debug/pprof/heap
收集 30 秒 CPU 配置文件
http://localhost:6060/debug/pprof/profile?seconds=30
使用调试=2收集程序配置文件
http://localhost:6060/debug/pprof/goroutine?debug=2
2.2 使用 API 调用进行收集
在节点控制台中键入相应命令,以收集或配置配置文件,如以下示例所示:
# Collect 30-second CPU profile> debug.cpuProfile("cpu.profile", 30)# Collect 30-second block profile> debug.blockProfile("block.profile", 30)# Set mutex profiling fraction> debug.setMutexProfileFraction(1)
2.3 使用 go tool pprof 进行收集
如果无法访问 pprof 网络界面,可以使用 go tool pprof 在本地生成和分析剖析结果。
识别可用的轮廓类型
支持的配置文件包括
allocs:过去所有内存分配的抽样。block:导致同步原语阻塞的堆栈跟踪。goroutine:当前所有 goroutine 的堆栈跟踪。 使用debug=2作为查询参数,以与未恢复的恐慌相同的格式导出。heap: 堆实时对象的内存分配采样。 您可以指定gcGET 参数,以便在提取堆样本之前运行垃圾回收。mutex:争用代理持有者的堆栈跟踪。profile:CPU 配置文件。 您可以在secondsGET 参数中指定持续时间。 获取配置文件后,使用go tool pprof命令来研究配置文件。threadcreate: 线程创建导致创建新操作系统线程的堆栈跟踪。trace: 跟踪当前程序的执行轨迹。 您可以在secondsGET 参数中指定持续时间。 获取跟踪文件后,使用go tool trace命令调查跟踪。
使用 go tool pprof 收集配置文件
go tool pprof http://localhost:6060/debug/pprof/<profiletype>
将 <profiletype> 替换为上述受支持的配置文件之一(如 heap, profile)。
命令示例
# Collect heap profilego tool pprof http://localhost:6060/debug/pprof/heap# Collect 30-second CPU profilego tool pprof http://localhost:6060/debug/pprof/profile?seconds=30# Collect goroutine profile with debug=2go tool pprof http://localhost:6060/debug/pprof/goroutine?debug=2