BugdrLog in
All problems
MediumGoDevOps / Infra · cgroups · containers · cpu · go · linux

Container CPU Limit Cgroup Detection

★ 0.0 (0 ratings)60 min0 engineers solved this

Your assignment

This is a small Go library that sizes the Go runtime's scheduler thread count to the CPU limit imposed on the process by a container runtime. Callers import the maxprocs package for its side-effect-free Set function or call it from init. Internally the internal/cgroups package parses the kernel mount table (mountinfo) to decide whether the host uses cgroup v1 or cgroup v2, then reads the matching CPU quota files (cpu.max for v2, cfs_quota_us and cfs_period_us for v1) through small typed helpers. The internal/runtime package converts the quota into a thread count, applies an optional minimum, and returns a status value. Mount table parsing lives in mountpoint.go, and the v2 logic is in cgroups2.go. Tests use fixture files under testdata that mimic /proc and /sys layouts.

What the team is seeing

incident log
Our service running in containers on newer servers keeps using every CPU core on the machine even though we set a lower CPU limit for each container. Under load it becomes sluggish and gets throttled by the platform. The same build behaves correctly on our older nodes.

Acceptance checks 1

  • Check 1

Discussion is locked — log in and complete this problem to join the discussion and rate your experience.