affinity

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package affinity pins a goroutine to a CPU.

A packet loop that migrates between cores loses its caches and, on a machine with more than one memory node, may end up a long way from the NIC. Pinning is also what makes a measurement mean anything: "four workers" is only a number if each one has a core to itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NUMANodeOf

func NUMANodeOf(cpu int) int

NUMANodeOf reports which memory node a CPU belongs to, or -1 if that cannot be told. It is for reporting: a run whose workers and NIC are on different nodes is worth knowing about before the numbers are believed.

func NUMANodeOfInterface

func NUMANodeOfInterface(ifname string) int

NUMANodeOfInterface reports which memory node a network interface's card is attached to, or -1 if that cannot be told.

func Parse

func Parse(s string) ([]int, error)

Parse turns a list like "4,6,8-11" into CPU numbers.

func Pin

func Pin(cpu int) error

Pin locks the calling goroutine to its operating system thread and moves that thread to the given CPU. It stays there until the goroutine ends.

The lock is what makes the pinning stick: without it the Go scheduler is free to run the goroutine on another thread, which is on another CPU.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL