Go: sysmon, Runtime Monitoring

Vincent
3 min readSep 13, 2020
Illustration created for “A Journey With Go”, made from the original Go Gopher, created by Renee French.

ℹ️ This article is based on Go 1.14.

The Go standard library dedicates a thread to watch after your application and help with bottlenecks your program could face. This thread, called sysmon, stands for system monitor, is not linked to any P in the G,M,P model, meaning it is not taken into account in the scheduler and therefore is always running. Here is an updated diagram with this special thread:

For more information about the G, M, P model, I suggest you read my article “Go: Goroutine, OS Thread and CPU Management.”

Also, you will not see this thread in the traces via the Go tool trace.

Scope

The role of this thread is wide and steps in with:

  • The timers created by application. The thread looks at the timers that are supposed to be running but are still waiting for running time. In that case, Go will look at the list of idle M and P in order to run them as soon as possible.
  • The net poller and the system calls. It runs the goroutines blocked in network operations.
  • The garbage collector if it has not run for quite a long time. If the garbage…

--

--