fix(worker): discard impossible cgroup v2 cpu samples - #7113
Conversation
The root cgroup usage_usec counter can return a torn per-cpu sum on some hypervisors. CGroupV2CPUMonitor divided the raw delta by the nominal interval and clamped only the top, so one bad read became a 1.0 or a large negative sample and the five-slot average marked an idle worker FULL for 2.5 s. Measure elapsed time around the reads, discard a delta that is negative or above elapsed x host cpus, and hold the last good sample on discard.
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings β view it in Devin Review. (Configure)
| start = time.monotonic() | ||
| cpu_usage_start = self._read_cpu_usage() |
There was a problem hiding this comment.
π‘ Pre-sample pauses suppress CPU load
Scheduler pauses before the first counter read inflate elapsed without adding measured CPU time. A busy worker can report artificially low load and accept excess work.
| start = time.monotonic() | |
| cpu_usage_start = self._read_cpu_usage() | |
| cpu_usage_start = self._read_cpu_usage() | |
| start = time.monotonic() |
Was this helpful? React with π or π to provide feedback.
|
|
||
| class CGroupV2CPUMonitor(CPUMonitor): | ||
| def __init__(self) -> None: | ||
| self._last_cpu_percent = 0.0 |
There was a problem hiding this comment.
π‘ First corrupt sample reports idle
When the initial counter delta is rejected, _last_cpu_percent remains zero. A saturated worker can advertise idle load until a valid sample arrives.
Prompt for agents
CGroupV2CPUMonitor initializes _last_cpu_percent to 0.0, but cpu_percent returns that value whenever an impossible delta is discarded. On startup there is no valid previous sample, so a busy worker is treated as idle for one or more rejected samples. Track whether a valid sample exists and handle the no-history case conservatively, such as retrying the counter read or returning a load value that cannot admit excess work. Preserve the existing last-good-value behavior after a valid sample has been recorded, and add tests for first-sample positive and negative torn reads on a saturated worker.
Was this helpful? React with π or π to provide feedback.
Problem: On some hypervisors the root cgroup
usage_useccounter returns a torn per-cpu sum, andCGroupV2CPUMonitor.cpu_percentturns that one read into a 1.0 or a large negative sample. Four such samples in the five-slot load average mark an idle worker FULL for 2.5 s, and a call that lands in that window gets no server.Fix: The monitor measures elapsed time around the two reads and discards a delta that is negative or above
elapsed x host cpus, since no host can produce either. A discarded sample returns the last good value instead of a fresh number, so the average is unchanged on idle and busy hosts alike.Fixes #7102. Supersedes #7103.
Context for reviewing and coding agents