Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions doc/adr/0005-reactive-live-admission.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ configured.**
`(inFlight+1) * footprint`. MemAvailable is instantaneous, so memory is checked
raw.
- **Far vs near the line.** Far from the reserve, jobs are admitted freely (cheap
jobs and bursts sail through). Near it, admission serialises: admit one, wait a
short **settle window** (default 3s) for the reading to reflect it, re-probe.
jobs and bursts sail through). Near it, admission serialises: every dispatch
decision takes one probe, and a runner that does not fit ends the round
(#192). The message loop keeps polling and the next message or empty poll
re-probes.
The near-line margin is not a separate tuned constant — it is one footprint
wide, implicit in the admission arithmetic.
- **Local admission and reporting.** `admitOne` checks headroom before each
Expand All @@ -52,8 +54,11 @@ configured.**
gate is the real limiter. The operator cannot set it.
- **Fail safe.** A probe error admits (the semaphore backstops; stranding
acquired work is worse than a brief over-admit) and reports a conservative
local capacity estimate of 1. Context cancellation unblocks a
parked admission so shutdown never hangs on a full host.
local capacity estimate of 1. Admission never blocks the
message loop (#192), so shutdown cannot hang on a full host. A runner is
charged the largest declaration among the known not-yet-started assignments
(the default job when none), and `JobStarted` replaces that charge with the
started job's real declaration.
- **Go decides, bash reads.** The admission decision lives in the Go listener
(ADR-0003 already scopes "the concurrency pool / capacity" to Go). The host
reading is a thin shell-out, `listener/host-probe.sh`, emitting `loadavg1 /
Expand Down Expand Up @@ -81,9 +86,11 @@ into device-count sizing with an explicit `mode: auto`.
- The coarse `1/nproc` footprint can under-admit genuinely cheap jobs on
small-core hosts (they are treated as ~one core each). A future measured /
adaptive refinement can tighten the footprint; it is not load-bearing today.
- There is a small settle latency near the line, by design (back-pressure). Real
waiting only happens when the host is actually full, where running more would
make every job slower.
- Near the line a shortfall is retried on the next message or poll rather than
immediately (back-pressure). Not dispatching only happens when the host is
actually full, where running more would make every job slower.
- An idle runner holds at most the largest known declaration until its
`JobStarted` arrives, so the host can briefly be over-reserved (#192).
- A co-tenant that grows *after* admission can briefly cross the reserve; reactive
admission corrects on the next decision, and ephemeral jobs finish and
self-heal, so the breach is a tolerated transient.
Expand Down
33 changes: 28 additions & 5 deletions doc/adr/0006-declared-job-cores.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ charges that declaration against a per-host core budget.**
label means recreating each host's set while it is idle.
- **Capacity.** The capacity advertised before GitHub assigns a job assumes the
default cost of 1, because a job's labels are known only once it is assigned.
A larger job then waits in `admitOne` on the host it was assigned to. The
A larger job is not admitted on that round and is retried on the next message (#192). The
default size is clamped to the host budgets like any other, so a host whose
RAM budget is under 4 GB still advertises one slot (#177).

Everything else in ADR-0005 stands: `reserve` is the only host knob, the
settle window, the internal safety ceiling, fail-safe probing, and Go deciding
internal safety ceiling, fail-safe probing, and Go deciding
while bash reads `/proc`.

## Alternatives
Expand All @@ -71,9 +71,32 @@ while bash reads `/proc`.
- Workflows own their cost declaration. A job that under-declares still meets
the loadavg check, so the host degrades rather than collapses.
- A runner is minted for one assignment but GitHub may give it a different
queued job. Committed cores therefore match in total, not job by job.
- Head-of-line: within one batch a large job that does not fit parks the
smaller jobs behind it until it starts.
queued job. Until `JobStarted` arrives, committed cores are a pessimistic
estimate (the largest known declaration per runner); after it, each runner
is charged the job it really took, matched by its JIT runner name, not by the
assignment it was minted for (#192).
- Head-of-line: within one batch a large job that does not fit ends the round;
later messages re-probe, so smaller jobs behind it start once it fits or the
budget frees (#192).
- A runner is minted before its job is known, so it is charged the largest
declared size among the known not-yet-started assignments (the default job
when none). `JobStarted` names the runner and the job it took; the charge
becomes that job's declared size, clamped to the budget. A `JobStarted` for a
runner the listener does not hold leaves every charge unchanged and is
logged; its job still leaves the known assignments, since it is no longer
waiting for a runner. A GPU runner keeps its card and is re-attributed
there, clamped to the budget stored for that card.
- One ledger owns the charge lifecycle (known assignment, runner charged,
started, exited). Committed totals are sums over the held runners, not
counters; a started or completed job id cannot return to the known
assignments while it is among the most recent 4096 retired ids (older ones
are forgotten, bounding memory); a runner name already held is refused; an exit releases only
its own record. The result does not depend on the order these events
arrive in (#192).
- Each dispatch mints a runner name of its own (the job id plus a per-dispatch
suffix), so a `JobStarted` for an earlier runner of a redelivered assignment
never names its replacement. A CPU runner is charged the size that passed
admission and keeps that probe's budget for the later clamp (#192).
- The label set on every cpu scale set is part of the routing contract. A new
`cpu-cores-<N>` value needs adding to `runner-types.yaml` and each host's
scale set recreated before workflows use it.
Expand Down
9 changes: 6 additions & 3 deletions doc/adr/0007-declared-job-vram.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ the GPU it chose.**
committed to running jobs plus the job's declaration fits the budget AND the
live free VRAM (`nvidia-smi`) is still at least `reserve`. The live check
counts processes the listener did not start. One GPU hosts several jobs
while their declarations fit. While no GPU fits, admission waits the settle
window and re-probes (ADR-0005).
while their declarations fit. While no GPU fits, the round ends after one probe and the next
message re-probes (ADR-0005, #192). A runner is placed and charged by the
largest VRAM declared among the known not-yet-started assignments, and
`JobStarted` adjusts the charge to the started job's declaration on the same
card.
- **Charge.** VRAM is charged after the worker slot is acquired and the
context checked (the #177 ordering), and released when the job exits or on
any failure path before it starts.
Expand Down Expand Up @@ -101,5 +104,5 @@ the GPU it chose.**
runners on one GPU); ADR-0005; ADR-0006; ADR-0002; ADR-0003.
- `listener/gpuprobe.go` (`CommandGPUProbe`, `jobVRAM`, `vramBudget`,
`pickGPU`, `gpuDevices`), `listener/listener.go` (`reconcile`, `admitGPU`,
`chargeGPU`, `releaseGPU`, `vramCapacity`), `listener/gpu-probe.sh`,
`vramCapacity`), `listener/ledger.go`, `listener/gpu-probe.sh`,
`listener/provision-job.sh`, `lib/runner-container.sh`.
16 changes: 7 additions & 9 deletions doc/arch/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,9 @@ <h2><span class="num">4.</span> Job 資料流</h2>
<line x1="440" y1="336" x2="440" y2="352" stroke="var(--arrow)" stroke-width="1.2" marker-end="url(#ah)"/>
<text x="448" y="348" font-size="7" fill="var(--container)">yes</text>

<!-- settle loop back -->
<!-- not admitted: round ends -->
<line x1="370" y1="310" x2="320" y2="310" stroke="var(--arrow)" stroke-width="1" stroke-dasharray="3,2"/>
<line x1="320" y1="310" x2="320" y2="284" stroke="var(--arrow)" stroke-width="1" stroke-dasharray="3,2"/>
<line x1="320" y1="284" x2="368" y2="284" stroke="var(--arrow)" stroke-width="1" stroke-dasharray="3,2" marker-end="url(#ah)"/>
<text x="280" y="298" font-size="7" fill="var(--text-3)">settle + re-probe</text>
<text x="250" y="313" font-size="7" fill="var(--text-3)">round ends, next msg</text>

<!-- 7. sem acquire + provision -->
<rect x="340" y="354" width="200" height="32" rx="4" fill="var(--bash-fill)" stroke="var(--bash)" stroke-width="1.2"/>
Expand Down Expand Up @@ -1056,7 +1054,7 @@ <h2><span class="num">13.</span> 反應式准入</h2>
<p class="desc">ADR-0005 的 CPU/RAM reactive live-admission。每個 job 准入前以 live host reading 判斷。</p>

<figure>
<svg viewBox="0 0 880 380" role="img" aria-label="Reactive admission flow: probe, admits(), settle, re-probe loop">
<svg viewBox="0 0 880 380" role="img" aria-label="Reactive admission flow: probe, admits(), admit or end the round">
<!-- capacityFor (local snapshot) -->
<rect x="30" y="20" width="380" height="150" rx="8" fill="var(--go-fill)" stroke="var(--go)" stroke-width="1.2"/>
<text x="220" y="44" text-anchor="middle" font-size="10" font-weight="600" fill="var(--go)">capacityFor (local snapshot)</text>
Expand Down Expand Up @@ -1101,16 +1099,16 @@ <h2><span class="num">13.</span> 反應式准入</h2>
<text x="822" y="210" text-anchor="middle" font-size="8" fill="var(--container)">admit</text>
<text x="765" y="200" font-size="7" fill="var(--container)">yes</text>

<!-- No path: settle + re-probe -->
<!-- No path: round ends -->
<line x1="660" y1="236" x2="660" y2="260" stroke="var(--arrow)" stroke-width="1.2" marker-end="url(#ah)"/>
<text x="670" y="252" font-size="7" fill="var(--warn)">no</text>

<rect x="580" y="262" width="160" height="28" rx="4" fill="var(--surface)" stroke="var(--bash-soft)" stroke-width="1"/>
<text x="660" y="281" text-anchor="middle" font-size="8" fill="var(--text-1)">settle (3s default)</text>
<text x="660" y="281" text-anchor="middle" font-size="8" fill="var(--text-1)">round ends</text>

<line x1="660" y1="290" x2="660" y2="312" stroke="var(--arrow)" stroke-width="1.2" marker-end="url(#ah)"/>

<text x="660" y="326" text-anchor="middle" font-size="8" fill="var(--text-3)">re-probe (loop)</text>
<text x="660" y="326" text-anchor="middle" font-size="8" fill="var(--text-3)">next message re-probes</text>
<!-- Loop back arrow -->
<line x1="660" y1="332" x2="660" y2="344" stroke="var(--arrow)" stroke-width="1"/>
<line x1="660" y1="344" x2="500" y2="344" stroke="var(--arrow)" stroke-width="1"/>
Expand Down Expand Up @@ -1321,7 +1319,7 @@ <h2><span class="num">16.</span> ADR 交叉引用</h2>
<tr>
<td><a href="../adr/0005-reactive-live-admission.md">0005</a></td>
<td>Reactive Live-admission</td>
<td>Per-job CPU/RAM admission, reserve headroom, settle window</td>
<td>Per-job CPU/RAM admission, reserve headroom, non-blocking per-round probe</td>
<td>hostprobe.go, host-probe.sh, listener.go (admitOne/capacityFor)</td>
</tr>
</table>
Expand Down
28 changes: 28 additions & 0 deletions doc/changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@ versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed

- **Admission no longer blocks the message loop** (#192): a job that does not
fit the reactive CPU/RAM budget or any GPU is now denied after one probe
and the listener keeps polling, instead of waiting inside admission while
an idle runner held the budget and no later message could free it. The
next message or empty poll re-probes and dispatches it. `Config.SettleWindow`
is removed. A new runner is charged the largest size declared among the
known not-yet-started assignments (the default job when none; for a GPU
host the largest VRAM declaration picks the card and is charged), and
`JobStarted` replaces that charge with the started job's declaration
(same card for VRAM), matched by the JIT runner name, not by the assignment
the runner was minted for. A `JobStarted` for a runner the listener does not
hold leaves every charge unchanged and is logged; its job still leaves the
known assignments. Until it arrives an idle runner holds the larger
charge, so a mixed batch packs after the jobs start.
Every message envelope, with or without statistics, now retries admission.
One `ledger` (`listener/ledger.go`) owns the charge lifecycle of every
runner: committed cores, GiB and VRAM are sums over the held runners, a
started or completed job id cannot return to the known assignments while it
is among the most recent 4096 retired ids, a
runner name already held is refused, an exit releases only its own record,
and a runner now gives up its charge before its assignment key can be
reused. A GPU re-attribution clamps to the budget stored for the pinned
card even when a later probe omits it. Every dispatch mints a runner name
of its own (the job id plus a per-dispatch suffix), so a delayed or
replayed `JobStarted` of an earlier runner cannot resize a replacement, and
a CPU runner is charged the size that passed admission, with the host
budget of that same probe kept for the later re-attribution, instead of a
later read of a probe snapshot the capacity reporter may have replaced.
- **Orphan reaping works again** (#186): since #168 the listener unit set
`HOME` to the runner home itself, so the SEC-3 guard (RUNNER_HOME must not
equal HOME) refused every orphan sweep and stranded containers and `jit-*`
Expand Down
11 changes: 9 additions & 2 deletions listener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,15 @@ Pin the builder images by digest in production via `RUNNER_KANIKO_IMAGE` /
- **Reactive live-admission (ADR-0005, #163):** by default the listener admits
each job only while every resource (CPU, memory) keeps a reserve headroom free
(default 10%, the one operator knob, upward-only). Local capacity snapshots
record admission headroom. A batch that would breach the reserve parks and
re-probes.
record admission headroom. A runner that would breach the reserve is not
admitted that round; the next message envelope (with or without statistics)
or empty poll re-probes (#192).
A new runner is charged the largest size declared among the known
not-yet-started assignments (the default job when none), since GitHub picks
its job only later. `JobStarted` re-attributes that charge, by JIT runner
name, to the job the runner really took; a GPU runner keeps its card and is
re-attributed on it. A `JobStarted` for a runner the listener does not hold
changes no charge.
The host reading is `host-probe.sh` (`HOST_PROBE_CMD`).
- **GPU VRAM admission (ADR-0007, #180):** `mode: vram` gates dispatch on
declared per-GPU VRAM and live reserve. Capacity snapshots estimate how
Expand Down
Loading