Skip to content

prototype(tier2): execution-service spike on ECS Fargate with workerd and Neon - #379

Closed
allisonmahmood wants to merge 8 commits into
mainfrom
prototype/tier2-exec-spike
Closed

allisonmahmood wants to merge 8 commits into
mainfrom
prototype/tier2-exec-spike

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Prototype, not for merge. Part of #311.

The self-hosted execution service on the Tier 2 map had only been argued from research: open-source workerd's Worker Loader in a credential-free task, callbacks through a loopback carrying a capability the guest never holds, one SERIALIZABLE transaction per mutation on Neon, and a pool of pre-started Fargate tasks as the wake path. This throwaway spike builds exactly that on ECS Fargate in us-east-1 against the Neon spike project so every number on the ticket could be measured instead of guessed.

What is here, all under prototypes/tier2-exec/ and outside the pnpm workspace:

  • handlers/: a patch repo's server/ as an agent would write it (contacts, abuse, probe), esbuild-bundled into one guest module per version.
  • exec/: the execution container: a Node supervisor (watchdog, RSS bound, kill and respawn) in front of workerd 1.20260925.1 with a loader Worker on the real workerLoader binding, one cached dynamic Worker per company/patch@version, globalOutbound bound to a refusing loopback, callbacks over ctx.exports props with the invocation id only.
  • host/: a stub of Patchy's runtime host: capabilities per attempt, /invoke with the four-slot cap, /callback opening the mutation's transaction, /stream SSE, three-way attribution, and the pool manager.
  • neon-bench/: the raw Neon measurements run from a one-off Fargate task in a scratch database.
  • infra/ and bench/: crane image builds (no docker), deploy and destroy, one script per measurement.

Measured from the host task in us-east-1 (full tables and the awkward list in RESULTS.md and neon-bench/RESULTS.md):

  • Fargate cold start to first invoke 24 s; bind of a pre-started task 16 ms; two simultaneous first opens 68 and 31 ms; a third with the pool empty waited 35 s.
  • Warm query 9 ms with no callback, 17 ms with one; the ten-callback mutation 92 ms p50, 106 p95, 116 p99 end to end including commit, 60 of 60 committed.
  • Rollback on a thrown handler leaves zero rows; a confirmed 40001 re-invokes and commits on the second attempt with a correct total; the fifth concurrent invoke gets busy; a replayed capability gets invocation_ended.
  • workerd RSS 53 MB idle, about 0.2 MB per in-flight invocation at 50 concurrent.
  • A tight loop is killed by the watchdog at 4.5 s and workerd is back in 36 ms; the other company's task never noticed, but sibling patches in the same task queued, died with the kill and then got busy until the respawn. A 200 MB allocation was only caught by the RSS bound on the third try.
  • From handler code the metadata endpoint, the filesystem and the internet are unreachable (the loopback refuses; nothing leaves workerd). The supervisor reaches task metadata but finds no credentials. Under the sealed security group the task cannot pull its image and ECS takes 4 m 49 s to say so.
  • Seven SSE documents flow over HTTP/2 through the ALB and the seventh blocks over HTTP/1.1; a stream held five minutes; a deployment drain cut a live stream at the 30 s deregistration delay before the host's goodbye.
  • Neon: warm connect 20 ms, query 2 ms, cold wake about 560 ms; four slots 154 commits/s against two slots 136 on one contended row; cancellation, lost commit reply and forced restart behaved as the model expects; the ADR-0009 path needs a SET-only role grant after each CREATE ROLE and DROP DATABASE under SET ROLE.

Round 2 (2026-09-25, same branch)

Astra's closure conditions from round 1, measured; tables under ## Round 2 in RESULTS.md:

  • PROCESS_MODE=company|patch in the supervisor. Under a tight loop in patch A, a sibling patch B in the same task committed 58 of 179 requests in company mode (121 errors, p99 5.0 s) and 177 of 179 in patch mode (2 busy, p99 329 ms, degraded but never stalled); the kill restarts only the offending process. The price is memory: about 45 MB per loaded patch process, 1006 MB aggregate for 20 loaded versions against 193 MB in company mode; processes are reaped after 60 s idle and respawn in 40 ms.
  • Deadline expiry mid-callback and mid-commit: handler_timeout with confirmed rollback, late callbacks refused by name, slot released; a lost commit reply is unknown_outcome and landed its rows five of five.
  • Per-call mutation keys written in the transaction: concurrent duplicates commit once, replays after a lost reply and after a host replacement are served from the table.
  • Company-to-task bindings and pool state in the database with an owner epoch; exec tasks refuse stale epochs; a host replacement adopted every task after one fix (the superseded host's idle sweep had to be fenced too).
  • Authorisation boundary: 14 of 14 refused as expected, including guest reaches for the supervisor and workerd ports.
  • Neon alone: neither an idle connection nor an idle-in-transaction session keeps the compute awake.

Run round 2 with ./bench/r2-run.sh after deploy.sh.

Try it

set -a; . ~/.config/patchy-cloud/aws-spike.env; set +a
export DATABASE_URL=$(grep '^DATABASE_URL=' ~/.config/patchy-cloud/neon-spike.env | cut -d= -f2- | tr -d "'\"")
cd prototypes/tier2-exec
npm install
./infra/build.sh      # bundle handlers, build and push two images with crane
./infra/deploy.sh     # task definitions, host service behind the ALB
./bench/run.sh        # every measurement through the ALB; raw output in bench/out/
./infra/destroy.sh    # stop the service and every exec task

The Neon bench alone: cd neon-bench && ./build.sh && ./run-on-fargate.sh (or ./run-local.sh for the cross-region contrast). A local loop without ECS is in the README.

Not breaking: nothing outside prototypes/tier2-exec/ changes.

Built by Claude Fable 5.1 via Claude Code (two subagents)

🤖 Generated with Claude Code

allisonmahmood and others added 5 commits September 25, 2026 17:26
… host stub

PROTOTYPE for #311. Runs locally against Neon; ECS wiring next.

Co-Authored-By: Claude Fable 5.1 <[email protected]>


PROTOTYPE for #311. Adds crane build, ECS deploy/destroy, the thirteen
measurement scripts, and the measured tables with the awkward list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
allisonmahmood and others added 3 commits September 25, 2026 18:32
… mutation keys, epoch fence, authz checks

PROTOTYPE for #311 round 2. Bench scripts and results follow.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
PROTOTYPE for #311 round 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…eded-host guard

PROTOTYPE for #311 round 2. RESULTS.md gains the Round 2 section: process
modes, deadline cleanup, mutation keys, ownership transitions, the
authorisation table and the Neon autosuspend probe run alone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant