花了很长时间,一直没看懂 golang
的runtime.futex
究竟是什么,后来搜索到linux
的futex
,用户空间互斥体,简单来说应该是锁
golang pprof profile 的结果:
(pprof) top
Showing nodes accounting for 4660ms, 68.83% of 6770ms total
Dropped 232 nodes (cum <= 33.85ms)
Showing top 10 nodes out of 153
flat flat% sum% cum cum%
1880ms 27.77% 27.77% 1880ms 27.77% runtime.futex /root/go/src/runtime/sys_linux_amd64.s
870ms 12.85% 40.62% 870ms 12.85% runtime.usleep /root/go/src/runtime/sys_linux_amd64.s
560ms 8.27% 48.89% 700ms 10.34% runtime.mapaccess1_faststr /root/go/src/runtime/hashmap_fast.go
380ms 5.61% 54.51% 390ms 5.76% runtime.siftdownTimer /root/go/src/runtime/time.go
250ms 3.69% 58.20% 250ms 3.69% syscall.Syscall /root/go/src/syscall/asm_linux_amd64.s
190ms 2.81% 61.00% 700ms 10.34% runtime.selectgo /root/go/src/runtime/select.go
150ms 2.22% 63.22% 150ms 2.22% runtime._ExternalCode /root/go/src/runtime/proc.go
130ms 1.92% 65.14% 130ms 1.92% runtime.memeqbody /root/go/src/runtime/asm_amd64.s
130ms 1.92% 67.06% 130ms 1.92% runtime.memmove /root/go/src/runtime/memmove_amd64.s
120ms 1.77% 68.83% 280ms 4.14% runtime.gentraceback /root/go/src/runtime/traceback.go
golang pprof block 的结果
(pprof) top
Showing nodes accounting for 0.15yrs, 100% of 0.15yrs total
Dropped 299 nodes (cum <= 0)
Showing top 10 nodes out of 15
flat flat% sum% cum cum%
0.14yrs 98.57% 98.57% 0.14yrs 98.57% runtime.selectgo
0 1.43% 100% 0 1.43% runtime.chanrecv1
0 0% 100% 0 0.73% github.com/robfig/cron.(*Cron).run
0 0% 100% 0.02yrs 13.69% main.(*Client).detailListLoop
0 0% 100% 0.01yrs 9.75% main.(*Client).shotLoop
0 0% 100% 0.01yrs 6.28% main.(*Client).wait10sBroadcastRun
0 0% 100% 0.02yrs 13.68% main.(*Client).writeLoop
0 0% 100% 0.02yrs 13.66% main.(*Client).writePump
0 0% 100% 0 0.57% main.(*Game).watchKeyCallBack
0 0% 100% 0.01yrs 5.57% main.(*Hub).RemoveNotInRoomClient
从 block 的 pprof 结果来看好像是selectgo
函数占比比较大
那么selectgo
是 linux 的select
还是 golang 的select
语法?
如果futex
是指selectgo
的占用的化,感觉好像没啥能优化的?