Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see where runtime.futex is coming from? It only has "System" as parent

Tags:

profiling

go

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.

profile screenshot

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?

like image 388
Dieter_be Avatar asked Apr 27 '15 00:04

Dieter_be


2 Answers

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.

like image 24
Jeremy Wall Avatar answered Oct 02 '22 14:10

Jeremy Wall


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()
like image 182
Oleg Neumyvakin Avatar answered Oct 02 '22 15:10

Oleg Neumyvakin