· AI dev tools

Kubernetes kubelet exposes PSI to diagnose CPU resource contention beyond utilization

The actual experience of a developer wrestling with slow AI inference requests often starts by checking CPU utilization, but this metric alone fails to reveal if the workload is merely waiting for…


The actual experience of a developer wrestling with slow AI inference requests often starts by checking CPU utilization, but this metric alone fails to reveal if the workload is merely waiting for processing time. This ambiguity spurred an investigation into Linux Pressure Stall Information (PSI), a tool that quantifies such waiting periods. A node can appear fully utilized whether two tasks are running on two CPUs or six tasks are fighting over those same two cores; the utilization numbers might look identical, yet the actual waiting time can differ drastically. PSI precisely measures this waiting. Kubernetes provides access to these PSI metrics via the kubelet, and these data points have remained consistent since Kubernetes version v1.36.

To confirm this difference firsthand, the author executed the identical workload under two distinct configurations on a Kubernetes node constrained to just two CPUs. In both tests, `kubectl top` reported the node consuming 2001m of CPU, indicating both CPUs were completely occupied. However, the CPU pressure registered was a mere 0.33% in the first scenario, contrasting sharply with 99.63% in the second.

CPU PSI is designed to report the proportion of time when at least one task was ready to execute but was stalled waiting for CPU time. This is presented as a percentage. For instance, an `avg10` of 25% signifies that, across approximately the preceding ten seconds, a task waited for about a quarter of that time. The kernel offers these averages spanning the last 10, 60, and 300 seconds (`avg10`, `avg60`, `avg300`), though the author favors `avg10` for its rapid response to workload shifts. Furthermore, PSI includes a `full` metric, indicating the portion of time when every single task was waiting simultaneously; this specific metric was not utilized in this study.

The kubelet's Summary API allows developers to view CPU usage alongside PSI for both the node and every individual pod and container: `kubectl get --raw "/api/v1/nodes//proxy/stats/summary" | jq '{cores: (.node.cpu.usageNanoCores / 1e9), psi: .node.cpu.psi}'`. For granular, per-pod data, one should look under `.pods[].cpu.psi`. If using Prometheus, the same signal is available via the kubelet's `/metrics/cadvisor` endpoint, labeled as `container_pressure_cpu_waiting_seconds_total`.

The experimental setup involved using a kind cluster hosted on a machine possessing four CPUs. Two of these CPUs were dedicated to the worker node, while the remaining two housed the control plane, thereby preventing the control plane from interfering with the test workload. The workload itself comprised a small pod executing busy loops, with each loop designed to consume one entire CPU whenever it secured access. The complete setup details can be found in the appendix. Following a 60-second stabilization period in each test, the node's CPU pressure was sampled twelve times, spaced ten seconds apart; the figures presented below represent the average of these twelve readings.

In Run A, which involved one pod running two loops—meaning each loop had dedicated access to a CPU—the worker node showed 2001m usage, confirming both CPUs were busy, yet the CPU pressure was only 0.33%. The loops experienced virtually no waiting time. Conversely, Run B featured three pods running six loops, forcing those six loops to compete for only the two available CPUs, which necessitated waiting for the others. While the CPU usage remained constant at 2001m, the CPU pressure spiked to 99.63%, indicating that nearly all the time, some loop was stalled waiting for CPU time. Both runs displayed a CPU(%) of 50%, a misleading figure because Kubernetes tallies the capacity of all four machine CPUs, unaware of the two-CPU restriction. Despite both runs utilizing the same two cores on the worker node, the CPU pressure leaped from under 1% in Run A to 99.6% in Run B. Run C, where a quarter of the node was utilized, still registered 75.2% pressure. Diving into the individual pod CPU usage revealed another layer of the issue: in Run A, the single pod consumed 1991m, whereas in Run B, each of the three pods utilized only between 616m and 708m, even though each still contained two busy loops. These lower individual numbers do not imply reduced CPU need; rather, they reflect the sharing of the two CPUs. While `kubectl top` fails to show this waiting, pod-level PSI exposed it: the three pods registered CPU pressures of 69%, 99.73%, and 99.79% in the final measurement.

The author also explored what happens when a workload possesses a CPU limit, even if the node has excess capacity. For Run C, the configuration returned to one pod with two loops, but its CPU limit was set to 500m. The worker node then used approximately 0.51 of its two CPUs, leaving three-quarters idle; `kubectl top` reported only 12% usage because it bases its calculation on the total four-CPU capacity. Nevertheless, the node's `some.avg10` averaged 75.23%. The 500m limit effectively capped the pod's consumption, even though the worker node had available CPU headroom. The two loops exhausted their allocated quota and were consequently throttled, a fact visible in the container's throttling counter, which showed it had been throttled across 1905 CFS periods since its initiation: `container_cpu_cfs_throttled_periods_total{container="spin",...} 1905`. The PSI documentation uses a CPU-limited pod as its illustration, but here, the throttling counter points to the pod's imposed limit rather than competition from other running workloads; thus, increasing node capacity would not alleviate this pressure as long as the pod's CPU limit remained fixed at 500m.

These three experiments illuminate precisely why one must examine CPU pressure alongside utilization when troubleshooting performance issues: in Run A (high utilization, low pressure), the CPUs are busy, but the workload fits comfortably, meaning utilization alone is not the root cause. In Run B (high utilization, high pressure), there is more runnable work than the CPU can handle, prompting an investigation into other scheduled items on the node, CPU requests, and placement strategy. Finally, in Run C (pressure on a pod with spare node CPU), the pod is likely constrained by its own CPU limit, necessitating a check of the throttling counters. The author cautions against adopting a universal PSI threshold; what is acceptable for a batch job could severely impact a latency-sensitive API, so comparison against the workload's established baseline and observing if pressure correlates with latency or queue depth is crucial.

For the inference services the author manages, latency can escalate due to several factors: increased internal service processing, CPU waiting time, or a delay in an external service call. These tests provided vital insight into what PSI contributes to the diagnostic toolkit. Should latency rise without a clear explanation from CPU utilization metrics, checking pod-level CPU pressure can reveal if contention or throttling is the underlying contributor. This check should always be cross-referenced with application metrics and traces before any final determination is made.

The appendix details how to replicate these scenarios: the tests were conducted on kind v0.33.0, utilizing Kubernetes v1.36.1, the release where PSI metrics achieved stability. Prerequisites include a Linux host supporting cgroup v2, a kernel with PSI enabled, Docker, kind, kubectl, and jq, all requiring at least four CPUs. To verify the host setup, one must check `stat -fc %T /sys/fs/cgroup` (expecting `cgroup2fs`) and `cat /proc/pressure/cpu` (expecting `some` and `full` lines). On macOS, Colima, an open-source utility that runs Docker Engine within a Linux VM (available via Homebrew), was employed: `colima start --profile psi-demo --runtime docker --cpu 4 --memory 8`, followed by running the checks inside the VM using `colima ssh --profile psi-demo --`.

A two-node cluster is established using the provided `kind-config.yaml`: `kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker`. The cluster is created via `kind create cluster --name psi-demo --image kindest/node:v1.36.1 --config kind-config.yaml --wait 180s`. To isolate the nodes onto separate CPUs, Docker's CPU restriction feature is used: `docker update --cpuset-cpus="0,1" psi-demo-control-plane` and `docker update --cpuset-cpus="2,3" psi-demo-worker`. The worker's CPU count is confirmed via `docker exec psi-demo-worker nproc` (expecting 2). Since the kind worker operates within a container, its node-level PSI originates from that container's cgroup, not the host's `/proc/pressure/cpu`, which explains why the system-wide CPU full line in `/proc/pressure/cpu` always reads zero. Metrics-server must be installed for `kubectl top`: `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.8.0/components.yaml`. A warning about the `--kubelet-insecure-tls` flag must be noted, as kind's

Why it matters

For developers optimizing latency-sensitive services, PSI provides crucial insight into why requests slow down beyond simple CPU load. This tooling helps diagnose resource contention that standard CPU metrics fail to capture in Kubernetes environments. Monitoring PSI allows teams to better tune workloads against actual node capacity.

Earlier coverage

Related coverage

Also worth reading

  1. next.js 16.6.0-canary.5 released, shows MCP endpoint, enables turbopackSeedCacheFromWorktree
  2. next.js 16.6.0-canary.4 released, adding Go syntax highlighting and Node.js 24 unit tests
  3. TypeScript 7.1-rc released for developers to download on npm
  4. next.js 16.6.0-canary.2 released, adds file uploads, updates docs, and more
  5. next.js 16.6.0-canary.1 released with 405 for forbidden Route Handler methods