Go Runtime

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

Go Runtime Scheduler

The Go runtime scheduler manages all goroutines that are created and need processor time. It binds operating system threads to logic processors, which, in turn, execute goroutines. As goroutines are created, they are placed in the scheduler's global run queue. From there, they are added to a logical processor's run queue and executed. Depending on the scheduling algorithm, a running goroutine can be stopped and rescheduled at any time. When a goroutine makes a blocking system call, the scheduler will detach the thread from the processor and create a new thread to service that processor. When a goroutine makes a network I/O call, the goroutine is detached from the logical processor and moved to the runtime network poller. Once the poller indicates a read or write operation is ready, the goroutine is assigned back to a logical processor to handle the operation.

Logical Processor

Go logical processors execute goroutines. Each logical process is individually bound to a single operating system thread.

SetMaxThreads

The Go runtime limits each program to a maximum 10,000 threads by default. This value can be changed by setting SetMaxThreads in runtime/debug package.

Goroutine Management

Goroutines and the Go Runtime

Memory Management and Garbage Collection

Memory Management and Garbage Collection