我有一个 Golang 程序,它只是实现了一个简单的业务逻辑:与服务器端程序建立套接字连接并保持业务心跳。但是当这个连接不传输任务数据时,pprof报告显示HeapAlloc大约14MB,而inuse_space显示只有512KB。造成如此大差异的原因是什么?
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
去工具 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