Understanding the Go Scheduler

nghiant3223.github.io

177 points by gnabgib 6 days ago


__turbobrew__ - 3 days ago

Make sure you set GOMAXPROCS when the runtime is cgroup limited.

I once profiled a slow go program running on a node with 168 cores, but cpu.max was 2 cores for the cgroup. The runtime defaults to set GOMAXPROCS to the number of visible cores which was 168 in this case. Over half the runtime was the scheduler bouncing goroutines between 168 processes despite cpu.max being 2 CPU.

The JRE is smart enough to figure out if it is running in a resource limited cgroup and make sane decisions based upon that, but golang has no such thing.

jasonthorsness - 3 days ago

It's always a sign of good design when something as complex as the scheduler described "just works" with the simple abstraction of the goroutine. What a great article.

"1/61 of the time, check the global run queue." Stuff like this is a little odd; I would have thought this would be a variable dependent on the number of physical cores.

kortex - 3 days ago

Fantastic writeup! Visualizations are great, the writeup is thorough but readable.

weiwenhao - 2 days ago

Your write-up is so detailed that I even feel like I could implement a complete golang scheduler myself

davidw - 2 days ago

I'd be interested in seeing a comparison of this and the BEAM/Erlang/Elixir scheduler by someone paying attention to the details.

90s_dev - 3 days ago

I heard that the scheduler is a huge obstacle to many potential optimizations, is that true?