【Go】性能优化

2022-11-19  本文已影响0人  如雨随行2020

常用命令

直接浏览器访问url

// url
https://confnode3.plaso.cn:7003/debug/pprof

点击allocs查看内存分配

image-20221120143137611

拉到底部可以看到内存分配信息

image-20221120143056588

点击goroutine查看正在运行的协程,以及数量;大致估算数量是否正确

image-20221120143723101

点击full goroutine stack dump查看是否有长时间阻塞的(搜索minutes)排查阻塞原因

使用命令行

查看cpu

go tool pprof https://confnode3.plaso.cn:7003/debug/pprof/profile
// top
// list <函数名>
// web

top后的参数

image-20221120154004970

list查看函数调用哪一行耗cpu

image-20221120154230589

web可以以图形化界面打开,前提要安装graphviz

查看内存

go tool pprof -inuse_space https://confnode3.plaso.cn:7003/debug/pprof/heap
   -inuse_space // 默认
   -alloc_space // 所有分配过的
   -inuser_objects // 对象
上一篇 下一篇

猜你喜欢

热点阅读