Golang性能调优

Posted by zengchengjie on Tuesday, February 8, 2022

性能调优(监控)

pprof

监控

线程监控

网络监控

  • golang原生获取网卡信息

  • gopack

    gopacket是经过cgo封装的libpcap的接口,这样便于我们在go语言中使用 libpcap。libpcap是Linux平台的抓包框架

火焰图

对比了很多方案后,这里强烈推荐性能监控工具 periscope 使用该工具即可方便地查看火焰图等数据:只需要集成几行代码即可通过火焰图查看服务的性能监控

import (
	"github.com/pyroscope-io/pyroscope/pkg/agent/profiler"
)

func main() {
    profiler.Start(profiler.Config{
		ApplicationName: "kafkamysql",
  
		// replace this with the address of pyroscope server
		ServerAddress: "http://localhost:4040",
  
		// by default all profilers are enabled,
		// but you can select the ones you want to use:
		ProfileTypes: []profiler.ProfileType{
			profiler.ProfileCPU,
			profiler.ProfileAllocObjects,
			profiler.ProfileAllocSpace,
			profiler.ProfileInuseObjects,
			profiler.ProfileInuseSpace,
		},
    })
}

访问我们的ip:4040端口,则可以看到集成了相关的服务的监控:

image-20220308100910523

点击查阅相关文档

该服务相关命令:

sudo systemctl start pyroscope-server
sudo systemctl enable pyroscope-server
sudo systemctl stop pyroscope-server

部署了一段时间,略微有点占CPU(可能是我的i3机器太弱了,暂时停了,有需要再拿出来排查问题)