maxprocs

package
v1.45.6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package maxprocs caps GOMAXPROCS to the Kubernetes CPU request so the Go scheduler doesn't create more OS threads than the pod is guaranteed.

Why not CPU limits / automaxprocs

Real-time media workloads (egress, ingress) intentionally omit CPU limits to avoid CFS throttling — even brief throttle events cause audio glitches and video frame drops. Without a limit the cgroup quota is "max", so libraries like uber/automaxprocs fall back to runtime.NumCPU (the full node). This package uses the CPU request instead, which reflects what the Kubernetes scheduler actually guarantees to the pod.

When a CPU limit IS set, the cgroup quota gives a tighter bound and Go (or automaxprocs) already derives GOMAXPROCS from it. This package still works in that case — it caps GOMAXPROCS down to the request but never increases it, so the stricter of (limit, request) wins.

Usage

The CPU request is read from the LIVEKIT_CPU_REQUEST environment variable, which should be populated e.g via the Kubernetes Downward API:

env:
  - name: LIVEKIT_CPU_REQUEST
    valueFrom:
      resourceFieldRef:
        containerName: <name>
        resource: requests.cpu

Without this variable the package is a no-op. A blank import is sufficient — init runs at process startup:

import _ "github.com/livekit/protocol/utils/hwstats/maxprocs"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install()

Install caps GOMAXPROCS to ceil(LIVEKIT_CPU_REQUEST) when that environment variable is set and valid. It never increases GOMAXPROCS beyond its current value. It is a no-op when the variable is absent. Runs at most once per process.

Types

This section is empty.

Jump to

Keyboard shortcuts

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