Skip to content

Index active account computers and sparse control log reads - #2046

Merged
callumalpass merged 1 commit into
mainfrom
server-do-hot-path-performance
Nov 28, 2026
Merged

callumalpass merged 1 commit into
mainfrom
server-do-hot-path-performance

Conversation

@callumalpass

@callumalpass callumalpass commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

The Portal loads the account's computers for both /v1/me and the delete-account dialog. Migration 0113 lets PostgreSQL find active connectors by account and creation time. The query still applies its installation and application joins.

Control-only log pulls already filter on kind <> 1 and paginate by sequence. A partial SQLite index on sequence lets workerd seek directly to those records. Existing actors build the index on their next initialization, which requires one scan of the existing item table. The PostgreSQL migration likewise builds its index on existing rows under the migration runner's locking rules.

PostgreSQL account computer list

PostgreSQL 18.6, 31 alternating AB/BA pairs after three warmups. Times are server-side execution from EXPLAIN (ANALYZE, BUFFERS, TIMING OFF). Both arms ran the production query and compared complete ordered results. The fixture includes a revoked connector, a recognized installation, and an installation with an unknown legacy app ID. The large case adds 25,000 connectors across 1,000 other accounts.

Unrelated connectors Median ms before → after p95 ms before → after Median shared buffers before → after
0 0.156 → 0.153 0.176 → 0.183 3 → 3
25,000 1.916 → 0.098 3.131 → 0.149 457 → 5

PostgreSQL kept the sequential scan for the small account. At 25,000 unrelated rows it switched from a sequential scan to a bitmap index scan on connectors_active_user_created_idx.

Durable Object control-only pull

Local workerd with the production SQLite schema, query, filter, and index. Each sample measures 64 byte-limited cursor reads in one request. Latencies and process CPU are batch averages per page. The table reports nearest-rank median and p95 over 15 alternating pairs after three warmups. A separate nine-pair V8 allocation sampling pass included objects collected during each batch. It covers the JS isolate heap. The cursor transferred one 256-byte binary payload per page in both arms.

Seed items Metric per page Before median / p95 After median / p95
8 Elapsed ms 0.0940 / 0.1374 0.0955 / 0.1563
8 Workerd CPU ms 0.0597 / 0.0812 0.0683 / 0.1108
8 Sampled JS heap bytes 743.94 / 830.81 738.63 / 785.19
25,000 Elapsed ms 3.1486 / 4.5424 0.0849 / 0.1090
25,000 Workerd CPU ms 3.0843 / 4.4429 0.0560 / 0.0880
25,000 Sampled JS heap bytes 726.38 / 811.88 725.81 / 749.88
Workerd storage metric Before After
Rows read per page, 8 seed items 14 7
Rows read per page, 25,000 seed items 25,006 7
Rows written per read 0 0
Rows written per ordinary append 1 1
Rows written per control append 1 2
Additional index storage with two seeded control rows 0 B 4,096 B

The SQLite plan changed from SEARCH items USING INTEGER PRIMARY KEY (rowid>?) to SEARCH items USING INDEX items_control_seq (seq>?). The small fixture shows a slight latency cost. These measurements exercise the storage operations on a local host. Full HTTP and WebSocket behavior is covered separately by conformance.

Reproduce

Run from the repository root on Linux with Node 24, Docker and pnpm 11.15.1. The PostgreSQL benchmark creates and drops its own schema.

pnpm install --frozen-lockfile
pnpm --filter @mdbase-dev/connect-protocol build
pg_container=$(docker run -d --rm -p 127.0.0.1::5432 -e POSTGRES_PASSWORD=bench -e POSTGRES_DB=bench_test postgres:18-alpine)
until docker exec "$pg_container" pg_isready -U postgres -d bench_test >/dev/null; do sleep 1; done
pg_address=$(docker port "$pg_container" 5432/tcp)
export MDBASE_CONNECT_TEST_DATABASE_URL="postgres://postgres:bench@${pg_address}/bench_test"
export MDBASE_CONNECT_DESTRUCTIVE_TEST_APPROVAL='I APPROVE MDBASE CONNECT DESTRUCTIVE POSTGRES TESTS'
pnpm --filter @mdbase/connect-server exec tsx scripts/bench-account-computers.mjs
docker stop "$pg_container"
(cd runtime/deploy/cloudflare-do && npm ci --no-audit --no-fund && node bench/control-pull.mjs)

Validation

  • pnpm ci:local passed every selected gate, including package audit.
  • rpnpm --filter @mdbase/connect-server test passed 1,533 tests. The remote runner skipped 997 tests, including those gated on PostgreSQL.
  • The local run with a dedicated PostgreSQL database passed all 230 selected tests across five files (account management, account backend, collection-creation migrations, devices and installation pairing). The benchmark passed its ordered result, visibility and query-plan assertions.
  • pnpm e2e passed daemon registration, read, disk writes, and sign-out refusal.
  • The packaged Worker passed all 20 conformance cases, four push cases and the runtime checks, including upgrade of an actor without the index. The initial disk-backed run missed the burst rate-limit assertion in ephemeral_streams. The same Worker and conformance binary passed with disposable SQLite state on tmpfs.

@callumalpass
callumalpass added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 8b8efa1 Nov 28, 2026
38 checks passed
@callumalpass
callumalpass deleted the server-do-hot-path-performance branch November 28, 2026 14:20
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