英文:
How can I see where runtime.futex is coming from? It only has "System" as parent
问题
使用go tool pprof
运行带有https://github.com/vimeo/statsdaemon的CPU分析文件,并输入“web”,我得到了一个包含大量“runtime.futex”的SVG分析文件。但是我看不出它是从哪里来的,它只是显示为“System”。
我想知道我的程序调用了哪些代码,导致了这么多时间花在了runtime.futex
上。
为了确保,我传递了'-nodefraction=0'
,这样它就不会在web svg视图中删除节点,尽管它显示“showing top 80 nodes out of 246 (cum >= 0.11s)”,也许这与此有关。
我尝试了https://code.google.com/p/gperftools/,结果显示相同。
可视化工具没有删除任何节点或边,但是“runtime.futex”仍然显示在“System”下面,这是根节点吗?
英文:
Running go tool pprof
with a cpu profile for https://github.com/vimeo/statsdaemon and typing "web" I get an svg profile with extensive use of "runtime.futex". But I can't see where it's coming from, it just says "System".
I want to know which code my program invokes, that causes so much time spent in runtime.futex
.
To be sure I passed '-nodefraction=0'
which makes it not drop nodes in the web svg view, though it says "showing top 80 nodes out of 246 (cum >= 0.11s)", maybe this is related.
I tried https://code.google.com/p/gperftools/ and it shows the same.
The viz drops no nodes or edges, but still "runtime.futex" just shows up under "System" and that's the root node?
答案1
得分: 8
一个futex或者叫做"快速用户空间互斥锁",是Linux系统调用,用于基本的锁定。我想Go运行时在内部会经常使用它。
没有看到代码的情况下很难确定,但对于具有大量协调和使用通道的高并发代码,可能确实是来自System的futex调用,而不是特定的函数。
英文:
A futex or "Fast user space mutex" is a linux system call that is used for basic locking. I imagine the go runtime uses it quite a bit under the hood.
Without seeing some of the code it's hard to say for sure but for highly concurrent code with a lot of coordination using channels it's possible that the futex calls really are coming from System and no particular function.
答案2
得分: 5
当我遇到这样的问题时,我使用了runtime/trace
,在其中我看到某个函数被频繁调用,而这个函数通过以下方式创建了一个新的ticker:
ticker := time.NewTicker()
但是没有通过以下方式停止它:
defer ticker.Stop()
此外,不要忘记停止定时器:
timer := time.NewTimer(duration)
defer timer.Stop()
英文:
When I've faced with such issue I've used runtime/trace
where I've see that some function was called very often and this function creates new ticker by
ticker := time.NewTicker()
but does not stop it by
defer ticker.Stop()
Also, don't forget to stop timers as well:
timer := time.NewTimer(duration)
defer timer.Stop()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论