性能调优实战 | 青训营笔记
这是我参与「第三届青训营 -后端场」笔记创作活动的第2篇笔记
简单记一下
性能分析工具 pprof-排查实战
- 将项目 github.com/wolfogre/go… 运行起来
go build - 浏览器地址:
localhost:6060/debug/pprof
- 终端输入:
go tool pprof "http://localhost:6060/debug/pprof/profile?seconds=10"
top
- flat: 当前函数本身耗时
- falt%: falt占CPU总时间的比例
- sum%: 上面每一行的falt%总和
- cum: 指当前函数本身加上其调用函数的总耗时
- cum%: cum占CPU总时间比例
-
注意:flat==cum函数中没有调用其他函数 flat==0,函数中只有其他函数的调用
-
list Eat查找具体函数
- web 界面方式查看
go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/heap"
- alloc_objects:程序累计申请的对象数
- inuse_objects: 程序当前持有的对象数
- alloc_space: 程序累计申请的内存大小
- inuse_space:程序当前占用的内存大小
- 分析goroutine
go tool pprof -http=:9010 "http://localhost:6060/debug/pprof/goroutine"
- 分析mutex
go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/mutex"
- 分析block
go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/block"
性能分析工具 pprof-采样过程和原理
>CPU
- 采样对象:函数调用和他们占用的时间
- 采样率:100次、秒,固定值
- 采样时间:从手动启动到手动结束