Skip to content

The queue does not count processors, so bounded commands together can oversubscribe the CPU #72

Closed

Description

@sourcehawk

Problem

The queue of bounding-heavy-commands counts memory and not processors. The commands that it runs together can ask for more processors than the machine has. A command with --cpus gets a CPU quota of that many processors, but the queue does not add the quotas of the running commands, so their sum can pass the number of processors. A command without --cpus gets no CPU quota at all.

This cannot freeze a machine, which is why the queue counts memory first. It makes every command and every agent session slow at the same time. On a 16-processor laptop with more than a dozen agent sessions, the load average was 26 to 36, and tasks waited for a processor 37% of the time (the some line of /proc/pressure/cpu, averaged over 5 minutes). Memory pressure was near zero. One bounded envtest suite ran three API servers at 70 to 85% of a processor each, beside other bounded builds and a bounded command with no quota.

Approach

Whether the second item is worth it is part of the work. Oversubscribed CPU is shared fairly by the kernel, so a queue on processors changes when each command finishes more than how much work the machine does. Measure the wall time of a batch of commands with and without it before merging.

Acceptance criteria

  • A command without --cpus runs under a default CPU quota where the hard cap is available.
  • If the processor count is added: a test with fake cpu.max files shows that a command waits while the running quotas and its own pass the number of processors, and starts when they do not.
  • The skill's text about --cpus and the wait matches.
  • The tests pass on Linux and macOS.

Context

Observed on 2026-09-30 while the stack #58 to #71 was under review. Related: #55 (memory counting), #57 (--check).

Activity

  1. sourcehawk commented on Oct 6, 2026

    @sourcehawk
    OwnerAuthor

    Result: the queue does not count processors

    Two items of this issue are done:

    The second item, a wait for processors, does not ship. I measured it as the issue asks, and it costs more than it gives.

    How I measured

    A script started each batch of bounded commands at the same moment, through the real wrapper, on a 16-processor machine. In one mode, each command entered the wrapper at once. In the other mode, the script let a command enter only when its --cpus, added to the --cpus of the running commands, was 16 or less, or when no command ran. That is the rule of the second item. A probe started /bin/true every 0.5 s and recorded the time, as a stand-in for a program outside the queue. Other agent sessions ran on the machine at the same time. Each batch ran two times, in the opposite order the second time.

    batch mode total time mean end CPU stall (some) probe p95
    3 cold Go builds, --cpus 8, each uses its quota no wait 165.9, 219.0 s 135.2, 214.7 s 59%, 76% 25, 78 ms
    wait for processors 165.9, 220.4 s 121.2, 163.3 s 52%, 63% 13, 53 ms
    1 cold Go build and 3 runs of a unit test suite, all --cpus 8; the suite uses 1 processor no wait 75.5, 69.2 s 44.8, 40.2 s 47%, 40% 3.8, 3.4 ms
    wait for processors 85.0 s 61.5 s 34% 2.7 ms

    A second run of the mixed batch with the wait took 386.9 s. A spike of load from another session came during that run, so the table does not use it.

    What the numbers show

    When each command uses its whole quota, the wait does not change the total time. The commands end at different times, not all at the end, so the mean end is 10 to 24% earlier, and the probe waits about half as long.

    When a quota is larger than the use, the wait keeps processors idle. A run without --cpus gets half the processors, also when its tool runs one process. The unit test suite in the table is such a command, and the third run of it waited for processors that the second run did not use. The total time was about 23% longer, and the mean end was about 50% longer. Agents that each run such a suite at the same time would take turns for no reason.

    The quota of a command tells the limit, not the use. So a wait that adds quotas helps one kind of command and harms the other.

    The skill text about --cpus and the wait still matches: the wrapper waits for its turn and for memory, not for processors, and cpus-free guides only the choice of a row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions