@
yufpga #6 嗯,谢谢, 应该是 block 问题
50 多个连接, 负载不是很大, 占了 15%~20% 的 CPU
查了下, profile,
970ms 21.85% 21.85% 970ms 21.85% runtime.futex
[futex 好像是 linux 的用户空间的快速锁](
https://zh.wikipedia.org/wiki/Futex)
应该是 cas 的模式吧...然后怀疑 futex 是 spinlock, 接着查询到 [futex 是支持 futex_wait 和 futex_wake 就是支持唤醒机制](
http://blog.sina.com.cn/s/blog_e59371cc0102v29b.html)
既然 futex 支持唤醒机制,为什么会这么耗 CPU, 在锁上耗 CPU,不是因为不断的尝试获取锁吗?
(pprof) tree
Showing nodes accounting for 3.53s, 79.50% of 4.44s total
Dropped 281 nodes (cum <= 0.02s)
Showing top 80 nodes out of 240
----------------------------------------------------------+-------------
flat flat% sum% cum cum% calls calls% + context
----------------------------------------------------------+-------------
0.41s 42.27% | runtime.futexsleep
0.31s 31.96% | runtime.systemstack
0.24s 24.74% | runtime.startm
0.01s 1.03% | runtime.unlock
0.97s 21.85% 21.85% 0.97s 21.85% | runtime.futex
----------------------------------------------------------+-------------
0.24s 55.81% | syscall.Write
0.19s 44.19% | internal/poll.(*FD).Read
0.33s 7.43% 29.28% 0.43s 9.68% | syscall.Syscall
0.09s 20.93% | runtime.reentersyscall
0.01s 2.33% | runtime.exitsyscall