Go Runtime: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:
==<tt>SetMaxThreads</tt>==
==<tt>SetMaxThreads</tt>==
The Go runtime limits each program to a maximum 10,000 threads by default. This value can be changed by setting <code>SetMaxThreads</code> in <code>runtime/debug</code> package.
The Go runtime limits each program to a maximum 10,000 threads by default. This value can be changed by setting <code>SetMaxThreads</code> in <code>runtime/debug</code> package.
==Goroutine Management==
{{Internal|Go_Language_Goroutines#Goroutines_and_the_Go_Runtime|Goroutines &#124; Goroutines and the Go Runtime}}

Revision as of 17:42, 16 January 2024

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 | Goroutines and the Go Runtime