简体   繁体   English

Golang pprof HeapAlloc 和 pprof heap inuse_space 数量的巨大差异

[英]Golang a huge difference in the number of pprof HeapAlloc and pprof heap inuse_space

I have a Golang program that just implements a simple business logic: establish a socket connection with the server-side program and maintain a business heartbeat.我有一个Golang程序,只是实现了一个简单的业务逻辑:与服务端程序建立socket连接,维护业务心跳。 But when this connection does not transmit task data, the pprof report shows that HeapAlloc is about 14MB, but inuse_space shows that it is only 512KB.但是当这个连接不传输任务数据时,pprof报告显示HeapAlloc大约是14MB,但是inuse_space显示只有512KB。 What is the reason for such a big difference?造成如此大差异的原因是什么?

pprof HeapAlloc: pprof 堆分配:

# runtime.MemStats
# Alloc = 1386704
# TotalAlloc = 49178232
# Sys = 15285372
# Lookups = 0
# Mallocs = 497504
# Frees = 494691
# HeapAlloc = 1386704
# HeapSys = 12124160
# HeapIdle = 9830400
# HeapInuse = 2293760
# HeapReleased = 8552448
# HeapObjects = 2813
# Stack = 458752 / 458752
# MSpan = 25680 / 32768
# MCache = 1736 / 16384
# BuckHashSys = 727065
# GCSys = 1149056
# OtherSys = 777187
# NextGC = 4194304
# LastGC = 1645580268115312488

go tool pprof mem.prof: go 工具 pprof mem.prof:

Type: inuse_space
Time: Feb 23, 2022 at 10:23am (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top5
Showing nodes accounting for 513.12kB, 100% of 513.12kB total
      flat  flat%   sum%        cum   cum%
  513.12kB   100%   100%   513.12kB   100%  compress/flate.(*huffmanEncoder).generate
         0     0%   100%   513.12kB   100%  compress/flate.init.0
         0     0%   100%   513.12kB   100%  runtime.doInit
         0     0%   100%   513.12kB   100%  runtime.main

What is the reason for such a big difference?造成如此大差异的原因是什么?

These are two different metrics.这是两个不同的指标。 See https://pkg.go.dev/runtime for the definition of value. value的定义见https://pkg.go.dev/runtime It also explains how to interpret the difference.它还解释了如何解释差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM