性能调优实战 | 青训营笔记

129 阅读1分钟

性能调优实战 | 青训营笔记

这是我参与「第三届青训营 -后端场」笔记创作活动的第2篇笔记

简单记一下

性能分析工具 pprof-排查实战

image.png

  • 终端输入:go tool pprof "http://localhost:6060/debug/pprof/profile?seconds=10"

image.png

  • top
  1. flat: 当前函数本身耗时
  2. falt%: falt占CPU总时间的比例
  3. sum%: 上面每一行的falt%总和
  4. cum: 指当前函数本身加上其调用函数的总耗时
  5. cum%: cum占CPU总时间比例
  • 注意:flat==cum函数中没有调用其他函数 flat==0,函数中只有其他函数的调用 image.png

  • list Eat 查找具体函数

image.png

  • web 界面方式查看 go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/heap"

image.png

  1. alloc_objects:程序累计申请的对象数
  2. inuse_objects: 程序当前持有的对象数
  3. alloc_space: 程序累计申请的内存大小
  4. inuse_space:程序当前占用的内存大小

image.png

  • 分析goroutine go tool pprof -http=:9010 "http://localhost:6060/debug/pprof/goroutine"

image.png

image.png

  • 分析mutex go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/mutex"

image.png

  • 分析block go tool pprof -http=:9000 "http://localhost:6060/debug/pprof/block"

性能分析工具 pprof-采样过程和原理

>CPU

  • 采样对象:函数调用和他们占用的时间
  • 采样率:100次、秒,固定值
  • 采样时间:从手动启动到手动结束 image.png

image.png

>Heap 堆内存

image.png