Skip to content

feat(workerd): ship one Workers build over cloudflare:sockets, and gate releases on edge CPU - #159

Merged
okomarov merged 1 commit into
mainfrom
cf-cpu-measure
Oct 19, 2026
Merged

okomarov merged 1 commit into
mainfrom
cf-cpu-measure

Conversation

@okomarov

Copy link
Copy Markdown

Reverses the unreleased switch of the workerd export to src/ over workerd's node:net (6a84f8b): on Cloudflare's network it costs more CPU per connection than cloudflare:sockets. The workerd condition resolves to cf/ again and the unreleased ./cloudflare-sockets subpath goes, so there is one Workers build and no option. 4.5.1 users see no change.

Adds a dispatch-only cpu job to workerd-edge.yml (cpu_rounds > 0). It measures CPU per connection from Workers Logs and fails when the default workerd build costs more than the latest npm release. The release process will run it before tagging.

Measurements

Two runs of 60 interleaved rounds, pooled. Each request connects, runs select 1 and ends. Values are cpuTimeMs from Workers Logs.

  • release is 4.5.1 from npm, which resolves to cf/ on Workers.
  • cf is this branch's cf/ build over cloudflare:sockets.
  • src is src/ over workerd's node:net and node:tls.

Supabase pooler, plaintext, fetch_types false

Build Median p95 p99 Within 10 ms
release 6 8 9 99%
cf 6 8 10 99%
src 7 8 9 100%

Supabase pooler, plaintext, fetch_types true

Build Median p95 p99 Within 10 ms
release 8 11 12 91%
cf 8 11 13 84%
src 10 13 15 70%

Neon, TLS, fetch_types false

Build Median p95 p99 Within 10 ms
cf 6 9 11 98%
src 8 11 23 92%

The rule was fixed before the runs: src loses if its median is at least 1 ms above cf's in both runs, with fetch_types on and off. It was. The two cloudflare:sockets builds differ by at most 1 ms either way. Workers Logs dropped about 15% of events at random.

Refs #15.

…te releases on edge CPU

The workerd export condition resolves to the cf/ build over
cloudflare:sockets again, for the package and for ./vercel, and the
./cloudflare-sockets subpath goes. Neither the node:net default nor the
subpath has been released, so 4.5.1 users see no change.

workerd's node:net is built on cloudflare:sockets but adds Node's stream
machinery, Buffer copies, nextTick scheduling and node:crypto's pbkdf2Sync
on the way, and that costs CPU on every connection. Measured on Cloudflare's
network (workerd-edge cpu job, two runs of 60 rounds, pooled, Workers Logs
cpuTimeMs per request; connect, select 1, end):

Supabase transaction pooler, plaintext, fetch_types false
  build                median  p95  p99  within 10 ms
  4.5.1 from npm            6    8    9   99%
  cloudflare:sockets        6    8   10   99%
  node:net                  7    8    9  100%

Supabase transaction pooler, plaintext, fetch_types true
  4.5.1 from npm            8   11   12   91%
  cloudflare:sockets        8   11   13   84%
  node:net                 10   13   15   70%

Neon, TLS, fetch_types false
  cloudflare:sockets        6    9   11   98%
  node:net                  8   11   23   92%

4.5.1 from npm runs the same cf/ code as this tree's cloudflare:sockets
build. node:net had a median at least 1 ms above cloudflare:sockets in both
runs with fetch_types on and off, which is the rule fixed before the runs.
With fetch_types on, 30% of node:net connections pass the Workers Free 10 ms
limit against 9 to 16% on cloudflare:sockets. A third run, with the variants
in a fresh random order every round and 4.5.1 also on Neon, put node:net
above cloudflare:sockets in 71 to 78% of request pairs and 4.5.1 at 48 to
51%, as the same code should be.

Cloudflare documents node:net as built on connect() and recommends neither;
pg, the driver its Hyperdrive docs recommend, also keeps its own adapter
over cloudflare:sockets (pg-cloudflare). There is no option to choose
node:net: one build per runtime. On compatibility dates before 2026-10-12
the cloudflare:sockets build reports a close-time rejection on most closes
(#1); at 2026-10-12 neither build does.

The CPU job is dispatched by hand (cpu_rounds > 0). It deploys the edge test
worker as a Preview and compares the latest npm release, the tree's
cloudflare:sockets build and the tree's node:net build, with fetch_types on
and off, against the free Supabase CI project through its transaction pooler
in eu-west-1, plus TLS rows against Neon. A Worker cannot verify the private
CA behind Supabase's certificates, so Supabase runs plaintext only. Each
round sends the variants in a random order. cpuTimeMs, wallTimeMs and
outcome come from the Workers observability API, matched by run id and a
numeric variant filter, and the report lists requests Workers Logs never
reported and requests that failed. The job fails when the shipped build
costs more than the latest release: median or p95 at least 1 ms higher, or
exceededCpu at least 2 percentage points more often, with fetch_types on or
off. The release process runs it before every tag.

The local workerd matrix and the edge scenarios drop the node:net build;
the CPU job keeps it as a reference row.
@okomarov okomarov changed the title Ship one Workers build, over cloudflare:sockets, and gate releases on Workers CPU feat(workerd): ship one Workers build over cloudflare:sockets, and gate releases on edge CPU Oct 19, 2026
@okomarov
okomarov merged commit d7442a4 into main Oct 19, 2026
19 checks passed
@okomarov
okomarov deleted the cf-cpu-measure branch October 19, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant