golang 程序 pprof futex 占用 27.77% 是否能有优化空间,应该怎么优化

2018-03-03 23:59:13 +08:00
 helloworld12

花了很长时间,一直没看懂 golangruntime.futex究竟是什么,后来搜索到linuxfutex,用户空间互斥体,简单来说应该是

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的占用的化,感觉好像没啥能优化的?

4774 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/434585

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX