深圳建网站好的公司,网站没有域名设置吗,做推广送网站免费建站,国内优秀html网站传统检测内存泄露可以看一下我这篇文章Gin框架接入Prometheus,grafana辅助pprof检测内存泄露-CSDN博客
pyroscope被Grafana收购,GPT来总结一下pyroscope的强大之处#x1f436;
pyroscope github地址 pyroscope与grafana的安装
docker compose安装#xff0c;这里我们其实…传统检测内存泄露可以看一下我这篇文章Gin框架接入Prometheus,grafana辅助pprof检测内存泄露-CSDN博客
pyroscope被Grafana收购,GPT来总结一下pyroscope的强大之处
pyroscope github地址 pyroscope与grafana的安装
docker compose安装这里我们其实可以不使用grafanapyroscope已经是一个很完整的产品但是我们在grafana里面可以配置数据源也可以在grafana里面查看grafana暂时还没有好的pyroscope dashboard
version: 3.8services:grafana:image: grafana/grafanacontainer_name: grafanaports:- 3000:3000networks:- monitoringdepends_on:- prometheuspyroscope:image: grafana/pyroscopecontainer_name: pyroscopeports:- 4040:4040networks:- monitoring networks:monitoring:driver: bridge 执行
docker-compose up -d 访问Pyroscope http://localhost:4040/ 我们可以看到go语言的各种性能指标与pprof检测的各类指标差不多 Gin框架中间件配置
我们在gin框架中间件中集成这个检测插件
ApplicationName: simple.golang.app.golang,用于在Pyroscope筛选服务 package initializationimport (awesomeProject3/middwareawesomeProject3/routergithub.com/Depado/ginpromgithub.com/gin-gonic/gingithub.com/grafana/pyroscope-go_ net/http/pprofruntime
)func Routers() *gin.Engine {r : gin.New()r.Use(p.Instrument())runtime.SetMutexProfileFraction(5)runtime.SetBlockProfileRate(5)pyroscope.Start(pyroscope.Config{ApplicationName: simple.golang.app.golang,// replace this with the address of pyroscope serverServerAddress: http://localhost:4040,// you can disable logging by setting this to nilLogger: pyroscope.StandardLogger,// you can provide static tags via a map:Tags: map[string]string{hostname: ginapp},ProfileTypes: []pyroscope.ProfileType{// these profile types are enabled by default:pyroscope.ProfileCPU,pyroscope.ProfileAllocObjects,pyroscope.ProfileAllocSpace,pyroscope.ProfileInuseObjects,pyroscope.ProfileInuseSpace,// these profile types are optional:pyroscope.ProfileGoroutines,pyroscope.ProfileMutexCount,pyroscope.ProfileMutexDuration,pyroscope.ProfileBlockCount,pyroscope.ProfileBlockDuration,},})return r
}模拟内存泄露
我们来模拟内存泄露 对下面接口压测压测粒度小一点来看pyroscope的作用。
我们生产项目中出现过一次严重的内存泄露例子如下图所示该接口qps非常高 pyroscope监控查看内存泄露 我们点击Single可以看到详细的火焰图以及性能瓶颈内存泄露的方法集代码也就是产生goroutine泄露的地方 结论
我们在使用golang 高并行处理下游任务的时候一定要对下游基础设施要有敬畏之心调用时限制goroutine的运行数量并且设置上context超时控制做好超时熔断措施做好监控警告下游基础设施如果达到瓶颈我们可对下游基础进行主从 水平扩容等。