最近组内一些Go服务碰到内存相关的问题,所以今天抽时间看了下Go pprof内存指标的含义,为后续查问题做准备。
内容主要来自于Go代码中对这些字段的注释,加自己的理解。理解不对的地方欢迎指正。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
Sys
HeapSys
HeapAlloc
HeapInuse
HeapReleased
HeapIdle
Alloc
TotalAlloc
Lookups = 0
Mallocs
Frees
HeapObjects
Stack = StackInuse / StackSys
MSpan = MSpanInuse / MSpanSys
MCache = MCacheInuse / MCacheSys
BuckHashSys GCSys OtherSys
NextGC
LastGC
PauseNs PauseEnd
NumGC
NumForcedGC
GCCPUFraction
DebugGC
|
查看方式
1 2 3 4 5 6 7 8 9 10 11 12
| import "runtime"
var m runtime.MemStats runtime.ReadMemStats(&m)
import _ "net/http/pprof" import "net/http" http.ListenAndServe("0.0.0.0:10001", nil)
|
下面随便找个服务来练手。
Top查看程序的VIRT
约为2.4G,RES
约为1.7G。
使用web pprof观察到的指标,可以对应着前文说的含义看看。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| # Sys = 1842916040 ~1.7G # HeapSys = 1711013888 ~1.6G # HeapInuse = 1237483520 ~1.18G # HeapAlloc = 1195472528 ~1.14G HeapInuse - HeapAlloc = 40M # HeapIdle = 473530368 ~451M # HeapReleased = 61063168 ~58.2M HeapIdle - HeapReleased = 393M
# Alloc = 1195472528 ~1.14G # TotalAlloc = 426616278424 ~397.3G
# Lookups = 0 # Mallocs = 2907819388 ~29亿对象数 # Frees = 2901808898 ~29亿对象数 # HeapObjects = 6010490 ~601万对象数
# Stack = 33390592 / 33390592 ~31.8M / 31.8M # MSpan = 13542744 / 19906560 ~12.9M / 18.9M # MCache = 55552 / 65536 # BuckHashSys = 2371870 # GCSys = 69398992 # OtherSys = 6768602
|
好,后续遇到内存有问题的案例,再来补充。
本文完,作者yoko,尊重劳动人民成果,转载请注明原文出处: https://pengrl.com/p/20031/