Repository navigation
feat(e11): record the REAL cold-acquire rate from the worker's counters (#306) - #311
Conversation
…rs (#306) coldAcquireRate is a latency-classification proxy: the share of Execs slower than SH_E11_COLD_LATENCY_MS. Measured against vmpool.Phases.Cold on the same runs it was wrong by 13x at c=8 (0.76 reported vs 0.056 true) and by ~250x at c=16 (~1.0 vs 0.0039). It cannot be repaired by tuning the threshold: Acquire is 0.3% of an Exec, so no threshold on end-to-end latency separates a warm acquire from a cold one. vmpool has always maintained the real figures in Stats.WarmAcquires/.ColdAcquires. Nothing outside vmpoolctl could read them, because the worker never exposed Stats at all. This adds that transport -- chosen over parsing SH_DIAG_PHASES lines because the counters are already authoritative and a log format is not a contract. microvm-worker now serves them on SH_DIAG_STATS_ADDR, opt-in and separate from SH_DIAG_PPROF so that obtaining counters does not require exposing heap contents, goroutine dumps and command lines. The handler is on its OWN mux, never http.DefaultServeMux: this package imports _ "net/http/pprof", whose handlers register on the default mux at import time, so /stats there would have smuggled rossoctl#308's documented pprof exposure in behind a different variable. A test pins that, and it was verified to fail against the default mux (all three pprof paths returned 200). The driver diffs the counters across each rung's own timed window -- they are process-lifetime totals, so a rung reading them absolutely would report every earlier rung's acquires as its own -- and records coldAcquireRateTrue beside the proxy rather than replacing it, so the two can be compared on one run before the proxy is renamed and retired (#306 step 3, deliberately not in here: that wants the comparison first). -1, never 0, when the rate cannot be determined: no acquires in the window, counters that went backwards because the worker restarted, or an arm with no microvm-worker to ask. Zero cold out of zero acquires would read as "replenishment kept up perfectly", the optimistic direction this file refuses everywhere else; -1 is outside [0,1]. Also records maxConcurrent, reported BY THE WORKER rather than assumed by the driver. Every E11 microVM rung ever recorded swept c to 64 against a 4-slot cap the driver never set and never wrote down, and at every point measured so far it was that, not the pool, which set throughput (rossoctl#305). Two proxyLimitations disclosures became false the moment the endpoint existed and are corrected: coldAcquireRate's "no stats endpoint exists", and standbysResident's "no pool introspection endpoint exists" -- the latter now says the endpoint exists while the field is still the proxy, so it cannot be misread as a pool statistic. Found by the tests, worth recording: the first draft wired SH_DIAG_STATS_ADDR into start_container_stack (whose worker is cmd/worker and has no pool at all), and the record-shape check was passing vacuously by matching 'coldAcquireRate' against its proxyLimitations disclosure string instead of the field, because the extraction was anchored at the 'arm' field, which appears AFTER it in the template. 481 bash checks (470 before), 9/9 Go packages, gofmt/vet/shellcheck/prettier clean, and experiments' microvm-predictions still passes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Strong PR. The core argument — that coldAcquireRate is a latency-classification proxy which cannot be repaired by tuning, because Acquire is 0.3% of an Exec — is well made, and the fix is the right shape: expose counters that were already authoritative rather than parse a log format. Two nits inline, no must-fix.
What I verified rather than took on trust:
- pprof isolation is real and tested.
diagStatsMuxreturns its ownhttp.NewServeMux(), andTestDiagStatsMuxDoesNotAlsoExposePprofasserts 404 on/debug/pprof/{heap,goroutine,cmdline}. Given this package doesimport _ "net/http/pprof", that separation is the whole ballgame, and the test has teeth. - No data race on the counters.
counters.snapshotis mutex-guarded and builds fresh maps forColdAcquires/Refusals, so the handler goroutine reading concurrently with the Exec hot path neither races nor leaks a shared map. Passingpool.Statsas a method value against theStats() Statsinterface is correct. - Init ordering matches the comment.
poolat main.go:440,maxConcurrentat 539–541, stats server at 546+, and the samemaxConcurrentreaches the session at 589 — so/statsreports the slot count actually in force, which is the #305 point. - Port choice avoids a collision: pprof documents
127.0.0.1:6060, stats defaults to127.0.0.1:6061, both loopback. ReadHeaderTimeoutis set (5s) on the stats server — gosec G112 clean, unlike the older pprofListenAndServe(addr, nil)beside it.- The
-1sentinel is properly pinned: no-acquires and counters-went-backwards both tested, and the rendered-JSON assertion checks-1arrives as a JSON number rather than the string"-1". The disclosed vacuous-pass fix (re-anchoring atrec = {and matching'coldAcquireRate': $cold_rate,with its interpolation) is a genuine improvement — the old anchor really would have matched theproxyLimitationsdisclosure string instead of the field. - The two corrected disclosures are accurate, and the
standbysResidentone errs in the right direction: it says the endpoint exists while the field is still the proxy, so it cannot be misread.
No secrets in the diff.
Areas reviewed: Go (HTTP diagnostic surface, concurrency, init order), Shell (driver + tests), security (endpoint exposure, pprof isolation, secrets)
Commits: 1, signed off ✓ · DCO passes
CI status: only DCO reported — the Go and shell suites do not appear to run on this branch. The PR body documents them run locally (481 ok / 0 FAIL, go test ./... 9/9, make lint clean); I did not independently execute them, so that half of the verification table is self-reported. Worth a CI-config look separately, not a blocker here.
Merge order: blocked on #310 merging first, per the stack.
Verdict: APPROVE — 2 nits, no must-fix.
| stats_after="$(vmpool_stats_acquires || true)" | ||
| if [ -n "$stats_before" ] && [ -n "$stats_after" ]; then | ||
| read -r warm_b cold_b _ <<<"$stats_before" | ||
| read -r warm_a cold_a max_concurrent <<<"$stats_after" |
There was a problem hiding this comment.
nit — read can clobber the -1 sentinel to empty.
read assigns the empty string to trailing variables it cannot fill, so a stats_after with fewer than three fields turns max_concurrent from -1 into "" — and that goes straight into the record template as a bare value:
'maxConcurrent': ,
^
SyntaxError: expression expected after dictionary key and ':'
I traced the reachability and it is narrow, which is why this is a nit and not a must-fix: the Go handler's print always emits exactly three fields, and every exception path in vmpool_stats_acquires exits before printing anything, so a malformed payload yields empty stdout and the [ -n "$stats_after" ] guard correctly holds -1. I checked the non-dict-coldAcquires case specifically — sum(None.values()) raises, stdout is empty, rc=1, guard holds.
So the exposure is a payload that succeeds and prints a short line, which today's handler cannot produce. A belt-and-braces max_concurrent="${max_concurrent:--1}" after the read still seems worth it, because the failure mode is a dead rung record rather than a bad number, and this file's whole thesis is that -1 must survive every path where the figure is unknown.
Worth noting the good half while I am here: the stats_before/stats_after split keeps max_concurrent real when the rate itself is undeterminable (worker up, no acquires in the window → rate=-1 slots=16). That is the right decomposition — the two facts fail independently and are recorded independently.
There was a problem hiding this comment.
Fixed — added max_concurrent="${max_concurrent:--1}" right after the read in b02ecd8.
|
|
||
| # Both figures on the same rung, so the proxy can be retired against evidence from one | ||
| # run rather than by assertion. The proxy is deliberately NOT removed yet (#306 step 3). | ||
| # From `rec = {` and not from the 'arm' field: 'arm' appears well AFTER |
There was a problem hiding this comment.
nit — indentation implies a block that is not there.
These comment continuations, and the rung_record= / case ... has_proxy statements below them, are indented two spaces while sitting at top level, so they read as if enclosed in an if that does not exist. Purely cosmetic, and consistent with make lint passing since shellcheck does not flag indentation.
There was a problem hiding this comment.
Fixed — de-indented the comment block, rung_record=, and the two case lines back to top level in b02ecd8.
…ndentation read leaves trailing variables empty when stats_after has fewer than three fields, which could silently turn max_concurrent from -1 into an empty string and break the JSON record template. Pin it back to -1 with a parameter-expansion default after the read. Also de-indent the coldAcquireRateTrue rung-record comments/case statements in the test file — they sat at top level but were indented as if inside a block that doesn't exist. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
`start_microvm_stack` never set `WORKER_MAX_CONCURRENT`, so the microVM worker kept `session.DefaultConcurrency` = 4. That sizes a FIXED pool of goroutines, one per concurrency slot, per worker process -- so every microVM rung ever recorded measured a 4-slot cap while the ladder swept c to 64, and the surplus c merely queued in front of it. The cap predicts the recorded points rather than merely being consistent with them, which is what makes it the cause: c=1 -> 1/55ms = 18.2 (measured 18.18); c=8 -> 4/62.2ms = 64.3 (67.76); c=16 -> 4/61.4ms = 65.1 (62.99). Lifting it to 16 measured 172.88 Exec/s where the default measured 62.99 on the same host -- 2.74x from one environment variable. - New `worker_max_concurrent_for` resolves the slot count and is a pure function of its argument and the environment, so the suite can drive it. The inline alternative is unreachable by any test, which is how the omission survived. - Defaults to the ladder's largest c, so slots and c move together. `SH_E11_WORKER_MAX_CONCURRENT` overrides it in BOTH directions: Task 1.3 sweeps the slot count against a fixed c, and reproducing the 4-slot cap deliberately is how a lifted one is compared against it on the same box. - An inherited `WORKER_MAX_CONCURRENT` is honoured as the lower-precedence source. That is how the 2.74x was measured before this existed, and since the driver now sets the name explicitly, ignoring an inherited one would silently overwrite the operator's value -- the same defect class as never setting it. - A malformed value REFUSES instead of falling back, because falling back restores the default 4 silently and re-records the artifact from a typo in the one variable that controls it. The refusal names the source it came from. - Below the ladder's largest c it WARNS: those rungs measure queueing against a smaller server, which is exactly how a 4-slot cap came to be published as a density ceiling. Allowed, never silent. - `SH_MAX_RUNS` now covers whichever is larger of the ladder's largest rung and the slot count. Sized from `max_c` alone it could sit below the slot count once the override can exceed it, and a worker with more slots than permitted runs refuses Execs mid-rung -- a refusal that reads as a VM-tier ceiling. - The resolved value and its provenance are logged, so a run's slot count is readable off its own log instead of inferred afterwards. Plan Step 4 (record MaxConcurrent per rung) needed no work: #311 already added `maxConcurrent` to the rung record, read back from the worker's own `/stats`. That is strictly better than recording what the driver believes it set, and the existing test for it is left as is. Verified: `bash deploy/microvm/tests/e11-density.test.sh` 0 failures, exit 0 (26 new checks); red-green confirmed by stashing only the driver change, which fails 3 of them. `make lint` exit 0. `pnpm -C experiments exec vitest run microvm-predictions` 3 passed; `predictions.json` untouched. No measurement is published here -- this only makes the next ladder honest. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Addresses rossoctl/moca-experiments#8 steps 1, 2 and 4. Step 3 is deliberately not here — see below.
Why the proxy cannot be tuned
coldAcquireRatecounts Execs slower thanSH_E11_COLD_LATENCY_MS. Againstvmpool.Phases.Coldon the same runs it was 13× off at c=8 (0.76 reported vs 0.056 true)and ~250× off at c=16 (~1.0 vs 0.0039). No threshold repairs it:
Acquireis 0.3% of anExec, so nothing about end-to-end latency separates a warm acquire from a cold one.
The transport
vmpoolhas always maintainedStats.WarmAcquires/.ColdAcquires. Nothing outsidevmpoolctlcould read them — the worker never exposedStatsat all. This adds that,chosen over parsing
SH_DIAG_PHASESlines because the counters are already authoritative and alog format is not a contract.
microvm-workerserves them onSH_DIAG_STATS_ADDR, opt-in and separate fromSH_DIAG_PPROF, so obtaining counters does not require exposing heap contents, goroutinedumps and command lines.
The handler is on its own mux, never
http.DefaultServeMux. This package imports_ "net/http/pprof", whose handlers register on the default mux at import time, so serving/statsthere would have smuggled #308's documented pprof exposure in behind a differentvariable.
TestDiagStatsMuxDoesNotAlsoExposePprofpins it, and I verified it fails against thedefault mux — all three of
/debug/pprof/{heap,goroutine,cmdline}returned 200.What the rung now records
coldAcquireRateTrue— diffed across the rung's own timed window. The counters areprocess-lifetime totals, so a rung reading them absolutely would report every earlier rung's
acquires as its own.
-1, never0, when it cannot be determined: no acquires in the window, counters thatwent backwards because the worker restarted mid-ladder, or an arm with no
microvm-workertoask. Zero cold out of zero acquires reads as "replenishment kept up perfectly" — the
optimistic direction this file refuses everywhere else.
-1is outside[0,1], so it cannever be mistaken for a rate.
maxConcurrent— reported by the worker, not assumed by the driver. Every E11 microVMrung ever recorded swept
cto 64 against a 4-slot cap the driver never set and never wrotedown, and at every measured point it was that, not the pool, which set throughput (session: DefaultConcurrency=4 is the per-process throughput cap — raising it beats adding workers (2.74x) #305).
The proxy stays, beside it. Renaming and retiring it is step 3, and that should follow a run
where both appear on the same rungs — not this PR's assertion.
Two disclosures that became false
proxyLimitationsclaimed "no stats endpoint exists" and "no pool introspection endpointexists". Both were true until this PR and false after it. Corrected — the second now says the
endpoint exists while that field is still the proxy, so it cannot be misread as a pool statistic.
Two mistakes the tests caught, recorded because they were instructive
SH_DIAG_STATS_ADDRintostart_container_stack, whose worker iscmd/workerand has no pool at all. The env assertion caught it.'arm'field, which appearsafter
coldAcquireRatein the template, it read only the tail and matched'coldAcquireRate'against itsproxyLimitationsdisclosure string rather than thefield. Now anchored at
rec = {and matched with its interpolation, and there is anassertion on the rendered JSON as well — a field can be in the template and still not
survive interpolation.
Verification
e11-density.test.shNone 4 Falsego build ./... && go vet ./... && go test ./...DefaultServeMuxmake lint(shellcheck, prettier, gitleaks)gofmt -lpnpm -C experiments exec vitest run microvm-predictionsNot scored here
Sealed prediction 3 cannot be scored from the proxy, and #259's runbook claim that "at
c≥16 every Exec pays a restore" is contradicted by the true counters: >99% of acquires were
warm. Both want the comparison run before anything is written into
EXPERIMENTS.md.🤖 Generated with Claude Code