golang Notes from a tech talk by Zaid Khan

  • The Go Scheduler is not a goroutine, its a function that is available at any given point of time.
  • A run queue cannot be used as there are a few issues:
    • Cannot determine the number of threads to actually spawn
    • Pushing to the run queue can be a high contention scenario
  • How Go does this
    • Go spawns OS threads = number of CPU cores
    • Go has a run queue for every thread spawned to hold go routines
    • Thread will pull a task from the run queue
    • If a thread is out of tasks, it can pull tasks from other run queues (work stealing)
    • If there a blocking task, go will spin up a new OS thread (or use a parked thread) and the run queue is transferred. This will ensure that number of parallel executing threads = cpu cores
    • Task letting go of the thread ?
    • When application is IO heavy ? we will end up with more OS threads and being parked ? Can’t we just park the task instead ? like cooperative scheduling