Repository navigation
feat(remote-worker): opt-in per-Exec timing line in both sandbox workers (#576) - #666
Conversation
…dbox worker (rossoctl#576) SH_EXEC_TIMING=1 makes BashRunner log one exec-timing line per Exec: req, workspace_key, start_ms, dur_ms (receipt to end), user_ms/sys_ms (the process tree's rusage), exit and err. Off unless exactly 1, like SH_DIAG_PHASES; when off the cost is one boolean check per Exec. No proto change: a deployment joins the lines on workspace_key and req. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…er (rossoctl#576) SH_EXEC_TIMING=1 makes vmpool.Runner log one exec-timing line per Exec in the container worker's format (req, workspace_key, start_ms, dur_ms, user_ms/sys_ms, exit, err), followed by tier="microvm", the phases ExecPhased already computes (acquire_us, resume_us, mount_us, run_us, destroy_us), cold and the VM. user_ms/sys_ms are the VM's CPU over the Exec: its pooled cgroup's cpu.stat read after the acquire and before the destroy (pooled cgroups are reused, so a difference), through an optional cpuReporter that firecrackerVM implements; -1 when not measured, never "no CPU". Off unless exactly 1. Scheduling, admission and teardown are unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Clean, well-scoped change. It's off by default, gated on exactly 1, needs no proto change, and the CPU delta across a reused pooled cgroup is handled correctly (read after acquire, before destroy, -1 when not measured). The tests cover on/off, format, CPU and the cpu.stat parser, and CI is green.
Inline comments are non-blocking. The main one: in streaming mode, the container worker's dur_ms does include time spent in a slow sink, which contradicts its comment. There's also a small cross-tier inconsistency: the container worker reports 0 for unmeasured CPU, the microVM worker reports -1.
| type BashRunner struct{} | ||
| type BashRunner struct { | ||
| // Timing, when set, logs one `exec-timing` line per Exec: its wall time from just before | ||
| // the child starts until Wait returns (so output still being delivered to a slow sink is |
There was a problem hiding this comment.
suggestion: This comment says output still going to a slow sink isn't counted, but in streaming mode it is. drain calls sink.Chunk inline, and wg.Wait() (which waits for both pumps) runs before cmd.Wait() and end. So dur_ms includes any back-pressure from a slow relay. Only the non-streaming emitBuffered at exit is left out. Either fix the comment (and the docs' "receipt to end") to say that streamed output is included, or take end from the child's exit if you want pure process time. As it stands, a benchmark could blame relay latency on the command.
| if end.IsZero() { | ||
| end = time.Now() | ||
| } | ||
| var userMs, sysMs float64 |
There was a problem hiding this comment.
suggestion: When there's no ProcessState (a start or pipe error), this reports user_ms=0.0 sys_ms=0.0. The microVM line reports -1 for "not measured", and its docs say -1 "means not measured, never no CPU". The PR's goal is one parser for both tiers, so use -1.0 here too (and let timingLine in runner_test.go accept -?). Otherwise a failed container Exec reads as a measured zero.
| return user, sys, gotU && gotS | ||
| } | ||
|
|
||
| // timingLog is nil unless the Runner was built with Timing (cmd/microvm-worker sets it from |
There was a problem hiding this comment.
nit: timingLog is never nil. It's always log.Printf, and the gate is Runner.Timing. This wording was copied from phaseLog, which really is nil-gated. Suggest: "timingLog is log.Printf; a variable so tests capture the lines. Runner.Timing gates the call."
| var timingLog = log.Printf | ||
|
|
||
| // logExecTiming emits the `exec-timing` line, the SAME format the container sandbox worker | ||
| // writes (internal/exec/runner.go logExecTiming, webchang 096a6df2), so a benchmark parses both |
There was a problem hiding this comment.
nit: webchang 096a6df2 is the fork's commit and doesn't exist in this repo (here it's cd9d18a). Drop the SHA. The file/function reference is enough.
| lines := captureTiming(t) | ||
| // No VM was acquired (an empty key is refused first), so no CPU was measured. | ||
| logExecTiming(7, "", time.UnixMilli(1000), 5*time.Millisecond, &Phases{}, 0, fmt.Errorf("refused")) | ||
| m := timingRe.FindStringSubmatch((*lines)[0]) |
There was a problem hiding this comment.
nit: If no line is logged, (*lines)[0] panics instead of failing the test. Add a len(*lines) != 1 check first, as in the test above.
Brings in upstream's 24 commits since the last merge: Valkey 9 in place of Redis (rossoctl#670), exec timing (rossoctl#666), both of IBM Bob's MCP filenames (rossoctl#676), mocactl --show-tools and workloads list, and the session turn counter. Conflicts, both in docs on what `sbx up` writes: the SBX0 spec and the sbx user guide. Resolved by keeping upstream's `.bob/mcp.json` and `.bob/settings.json` and this branch's OpenCode `skill` deny (98cc955). The merged code already does both. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Summary
Closes #576: an opt-in, cheap per-Exec timing line in both sandbox workers,
SH_EXEC_TIMING=1, off by default. When off,the cost is one boolean check per Exec; scheduling, admission and teardown are unchanged. No proto change.
internal/exec,cmd/worker): the line above, with the command process tree's CPU (rusage).internal/vmpool,cmd/microvm-worker): the same fields in the same order, so one parser readsboth tiers, then
tier="microvm", the phasesExecPhasedalready computes (acquire_us resume_us mount_us run_us destroy_us),coldand the VM.user_ms/sys_msare the VM's CPU over the Exec, from its pooled cgroup'scpu.statread after the acquire and before the destroy (pooled cgroups are reused, so a difference), through anoptional
cpuReporterthatfirecrackerVMimplements;-1means not measured, never "no CPU".docs/reference/configuration.md, both worker sections.This code has run in a fork through a set of SWE-bench benchmarks on P6 (one c5.metal host, both tiers, several
thousand Execs per tier); every per-Exec figure there comes from this line, e.g. a microVM adding about 55–58 ms per
Exec over a container, and the phase breakdown of a microVM Exec. The commits here are the fork's two, rebased on
main unchanged (the same added and removed lines), with this repo's commit format and sign-off, plus the docs.
Checklist
git commit -s).make lintand the tests for the touched packages pass:go vet ./...andgo test ./...inremote-worker(and
-raceforinternal/exec,internal/vmpool,cmd/worker,cmd/microvm-worker); new testsTestTimingLogsOneLinePerExec,TestTimingCountsChildCPU,TestTimingOffByDefault,TestRunnerTimingLogsOneLinePerExecWithTheVMsCPU,TestRunnerTimingIsOffByDefault,TestRunnerTimingMarksUnmeasuredCPUAsMinusOne,TestWorkspaceRunnerExecTiming.docs/reference/configuration.md(both sandbox worker sections).make check-linkspasses (212 files, 0 broken).Assisted-By: Claude Code