code
Thread Cache Malloc 線程級別的內存管理模式
最大化內存使用率,最小化分配時間
圖片來源 https://wallenwang.com/2018/11/tcmalloc/#ftoc-heading-16
記憶體分配
內存碎片處理
套件連結: https://golang.org/pkg/net/http/pprof/
cpu: cpu profile 是在哪邊花費CPU的時間。
heap: 記憶體當下以及過去的使用情況,並檢查記憶體洩漏
「Heap」 由於是動態配置的記憶體空間,其存活時間不規律不可預測的,故需使用者自行回收空間。
所以若GC處理不好,就會發現有程序狂吃記憶體的情況。
threadcreate: Thread的線程
goroutine: Goroutine profile 報告所有目前 goroutine的 stack追蹤。
「stack」用來儲存 Value Types (Primitives)的地方,其特性是 LIFO (後進先出),用來儲存物件的 stack 與 run-time 的 call stack 運作原理是一樣的,run-time 的 stack frame 包含了:
block: block profile 顯示 goroutine在哪裡阻塞(含timer channels)的等待。預設是關閉的,需要使用 runtime.SetBlockProfileRate 去開啟它。
mutex: Mutex profile 報告鎖的競爭. 如果您認為由於互斥鎖爭用而無法充分利用CPU. 預設是關閉的,需要使用 runtime.SetMutexProfileFraction 去開啟它。
Run on 之後 http://localhost:6060/debug/pprof/