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 ¶
Types ¶
This section is empty.