V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
helloworld12
V2EX  ›  问与答

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

  •  
  •   helloworld12 · 2018-03-03 23:59:13 +08:00 · 4839 次点击
    这是一个创建于 2455 天前的主题,其中的信息可能已经有所发展或是发生改变。

    花了很长时间,一直没看懂 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的占用的化,感觉好像没啥能优化的?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5444 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 03:23 · PVG 11:23 · LAX 19:23 · JFK 22:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.