Parallel Runner Design #
This note scopes Phase 5 Step 1: add multithreaded execution without changing the current CLI, summary JSON, or workflow ABI contracts.
Goals #
- scale single-node throughput with worker threads
- preserve the current
run/validatebehavior and output contracts - keep workflow guests isolated with instance-per-thread ownership
- make the single-thread path remain valid as the correctness baseline
Current Constraints #
The current runner is intentionally single-threaded:
src/runner/executor.zigdrives all execution modes from one dispatch loopsrc/runner/context.zigcreates one sharedstd.http.Client, one shared gRPC client, one TLS context, and one shared store for the whole runsrc/template.ziguses an unsynchronizedVarStoresrc/workflow/vu.zigandsrc/workflow/host.zigkeep mutable per-VU state in one Wasm instance, cookie jar, PRNG, and variable storesrc/runner/metrics.zigserializes all metric updates through one mutexedMetricsAggregatorsrc/runner/control.zigalready exposes process-global atomic stop flags and can stay the cross-thread stop mechanism
These constraints are good news for Phase 5 because the mutable workflow state is already grouped per VU. The main work is separating process-wide state from per-worker state and removing the global metrics hot lock.
Proposed Execution Model #
Use a coordinator plus worker threads.
- The coordinator owns run timing, progress cadence, threshold abort checks, and final summary merge.
- Each worker owns:
- one HTTP client
- one gRPC client
- one TLS context / connection pool
- one metrics shard
- a fixed set of VUs
- Workflow VUs stay thread-affine. A Wasm instance is created, used, recreated, and destroyed on one worker only.
setup.*data becomes immutable after setup. Workers clone it into per-VU stores and only mutatevu.*/iter.*locally.
Scheduling By Mode #
Constant VUs #
- Assign VU slots to workers up front with a stable
slot % thread_countmapping. - Each worker runs its own local loop over its assigned slots.
- This keeps request order deterministic per VU and avoids work-stealing for the simplest mode.
Constant Arrival Rate #
- Keep one coordinator-side arrival ticker.
- The coordinator emits iteration tickets into per-worker deques using round-robin or least-lag assignment.
- Workers pop local tickets first and optionally steal from neighbors when idle.
- Drop accounting stays in the coordinator because it already owns the global schedule.
Ramping VUs #
- Pre-allocate the full VU set.
- The coordinator updates an active-VU watermark as stages advance.
- Workers skip local slots above the current watermark.
Metrics Plan #
Replace the global hot mutex with shard-local mutation plus periodic merge.
- Introduce
MetricsShardwith the same counters and histograms currently stored inMetricsWindow. - Each worker mutates only its local shard with no cross-thread locking.
- The coordinator merges shards for:
- progress logging
abort_on_failthreshold checks- final summary generation
The merge path can reuse most of the existing summary code if MetricsWindow gains mergeFrom.
Transport And Runtime Ownership #
std.http.Clientshould be worker-local, not shared across threads.- The gRPC C++ client wrapper should also be worker-local to avoid hidden cross-thread constraints.
TlsContextand connection pools become worker-local because they currently wrap mutable connection state.- WAMR / wasm3 lifecycle remains instance-per-VU. No Wasm instance sharing across threads.
Workflow Recovery Rules #
Recovery stays local to the owning worker.
- recreate the same VU on the same worker
- activate spare VUs from the same worker's local capacity first
- report poisoned workers and unhealthy VUs via shard metrics, then merge globally
This keeps the existing recovery logic conceptually intact and avoids cross-thread handoff of partially failed guests.
Rollout Sequence #
- Extract immutable run inputs from
Sessioninto a coordinator-owned run plan. - Add
WorkerContextwith per-worker clients, TLS, and metrics shard. - Teach metrics to merge shard state into the existing summary format.
- Port
simplemodeconstant-vusfirst. - Port
constant-arrival-ratewith coordinator-issued tickets. - Port
ramping-vus. - Port workflow mode and keep recreate / poison logic thread-local.
Verification Plan #
- compare single-thread and multithread summaries for the same deterministic fixture
- run
1,2, and4thread parity checks for thresholds and request counts - verify one VU never changes owning worker during a run
- stress recovery paths with poisoned workflow VUs under multithreaded execution
- measure lock contention before and after shard-based metrics
Non-Goals For Step 1 #
- distributed coordinator / agent execution
- plugin ABI changes
- gRPC streaming
Those belong to later Phase 5 and Phase 6 work after single-node threading is stable.