性能分析
对golang应用运行时占用内存和cpu的大小和时间进行统计分析
工具
- go自带 net/http/pprof
方法
web应用
运行时开启监控
_ "net/http/pprof"
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
使用beego 自带了这个功能,需要配置如下:
编辑app.conf文件,开启监控功能.
EnableAdmin = true
在main.go
加入import _ "net/http/pprof"
web页面查看
通过访问localhost:6060/debug/pprof
查看简单页面
go 命令详细分析
在项目目录下运行命令:
- go tool pprof http:127.0.0.1:6060/debug/pprof/profile
这个命令会运行30s,分析这段时间内cpu的使用
- go tool pprof http:127.0.0.1:6060/debug/pprof/heap
这个命令会生成内存占用分析
执行以上命令后会进入一个交互式模式,可以输入一