Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 2.62 KB

profiling.md

File metadata and controls

62 lines (47 loc) · 2.62 KB

Processor and Thread and goroutine

  • P - processor, a resource that is required to execute Go code. 一般一个进程
  • M - worker thread, or machine. 根据cpu情况创建, 一般小于10个线程, 请求越多Thread越多, goroutine越多Thread也越多
  • G - goroutine.
  • Each goroutine (G) runs on an OS thread (M) that is assigned to a logical CPU (P)

flow

profiling data

Predefined profiles by runtime/pprof package

  • cpu: 查看cpu profile
    • go tool pprof main http://127.0.0.1:6060/debug/pprof/profile
    • CPU profile determines where a program spends its time while actively consuming CPU cycles
  • heap:
    • go tool pprof main http://127.0.0.1:6060/debug/pprof/heap
    • Heap profile reports memory allocation samples; used to monitor current and historical memory usage
  • threadcreate:
    • Thread creation profile reports the sections of the program that lead the creation of new OS threads.
  • goroutine:
    • wget http://localhost:6060/debug/pprof/trace?seconds=5
    • Goroutine profile reports the stack traces of all current goroutines.
  • block:
    • Block profile shows where goroutines block waiting on synchronization primitives.
    • Block profile is not enabled by default; use runtime.SetBlockProfileRate to enable it.

pprof visualization tool

  • graphviz: brew install graphviz
  • go tool pprof -http=:8080 ./pprof.pprof.samples.cpu.001.pb.gz

gin pprof middleware

  • go get github.com/gin-contrib/pprof