
由于海外业务的特殊性,峰值流量经常是发生在国内夜间,往往出现性能问题时,开发可能都在睡觉,早上才能发现机器性能告警,但此时现场已经不复存在,性能分析难上加难,效率比较低。
持续分析(Continuous profiling)是在生产环境中持续 收集应用程序性能数据,并将这些数据提供给开发人员进行深入分析的过程。
另外我们可能需要不同时段的profile进行对比,进行比较才能发现问题,比如内存泄露的问题。
Pyroscope是一个开源的持续分析系统,使用Go语言实现。服务端使用web页面查看,提供丰富的分析的功能,客户端提供Go、Java、Python、Ruby、PHP、.NET等多种语言的支持,并且支持PUSH、PULL两种采集方式。

目前go SDK支持以下指标
ProfileCPU ProfileType = "cpu"
ProfileInuseObjects ProfileType = "inuse_objects"
ProfileAllocObjects ProfileType = "alloc_objects"
ProfileInuseSpace ProfileType = "inuse_space"
ProfileAllocSpace ProfileType = "alloc_space"
ProfileGoroutines ProfileType = "goroutines"
ProfileMutexCount ProfileType = "mutex_count"
ProfileMutexDuration ProfileType = "mutex_duration"
ProfileBlockCount ProfileType = "block_count"
ProfileBlockDuration ProfileType = "block_duration"官方文档说明性能损耗在3~5%之间,比其他的分析平台要低很多。
默认每 15 秒收集一次性能数据并上传,可调整。
可以选择火焰图

也可以选取不同的时间段进行比较, 左右的图形的时间只需在时间线上拖拽选取即可。

还可以进行diff视图进行分析(内存泄露需要用到)

server端主要是收集各个SDK端发送过来的数据并提供UI界面进行分析。
我本地是安装了docker,所以直接运行docker镜像
docker pull grafana/pyroscope:latest
docker network create pyroscope-demo
docker run --rm --name pyroscope --network=pyroscope-demo -p 4040:4040 grafana/pyroscope:latestpyroscope.Start(pyroscope.Config{
ApplicationName: "scope_demo2",
// replace this with the address of pyroscope server
ServerAddress: "http://localhost:4040",
// you can disable logging by setting this to nil
Logger: pyroscope.StandardLogger,
// you can provide static tags via a map:
Tags: map[string]string{"hostname": "song_mac"},
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,
},
})
fmt.Println("Pyroscope started")综上所述,Pyroscope 作为一款开源的持续分析系统,为解决海外业务性能分析困境提供了有效的方案。它支持多种语言,具备丰富的分析功能与多样的采集方式,性能损耗低。
通过其提供的多种指标,如 CPU 使用率、内存使用情况、并发性能指标等,开发人员能够深入剖析应用程序性能。无论是火焰图、链路图,还是时段对比及 diff 视图等分析方式,都为性能优化提供了有力支持。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。