Skip to content

Marten.ScaleTesting: daemonload over pooled sharded databases — O(databases) connection gate (#4882, epic jasperfx#486 WS6)#4890

Merged
jeremydmiller merged 1 commit into
masterfrom
feat/4882-sharded-daemonload
Jul 7, 2026
Merged

Marten.ScaleTesting: daemonload over pooled sharded databases — O(databases) connection gate (#4882, epic jasperfx#486 WS6)#4890
jeremydmiller merged 1 commit into
masterfrom
feat/4882-sharded-daemonload

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Closes #4882 (epic #486 WS6). Stacked on #4887 (feat/4684-batch-instrumentation) — review/merge that first; this PR's own diff is the top two commits.

What's here

Extends daemonload (#4875) from single-database to sharded multi-tenancy with database pooling:

  • --databases N creates scaletest_dl_shard_0..N-1 on the same server (--wipe drops them WITH (FORCE) first), builds the store with MultiTenantedWithShardedDatabases (registry in the master DB's scaletest_daemonload schema, UseExplicitAssignment), assigns tenants round-robin with explicit placement, and runs one projection daemon per shard (sharded tenancy has one MartenDatabase per shard; the default-tenant daemon overload is invalid there)
  • Per-database pg_stat_activity sampling — new ShardConnectionSampler polls once per interval on the maintenance DB and groups the store's Application-Name-attributed backends by datname (ShardedTenancyOptions.ApplicationName stamps every pooled connection string). Master/registry DB reported separately
  • --max-connections enforced per shard database (the O(databases) gate)
  • Per-tenant catch-up across all shards — every tenant's per-tenant progression rows must reach that tenant's own sequence ceiling in its home shard
  • Database-affine placement sanity — each tenant's mt_events_sequence_{tenant} must exist in exactly its assigned shard; foreign-shard or missing-at-home sequences fail the run as cross-shard bleed

--databases 1 (default) is the untouched original single-DB WS2 scenario (regression-verified).

Measured (local reduced scale — sibling agents share this Postgres; full scale is a CLI-knob rerun)

daemonload --databases 2 --tenants 25 --projections 2 --duration-seconds 60 --wipe --max-connections 16

Metric Value
Tenant agents 50 (25 × 2), 13/12 tenants per shard
Events appended / rate 11,560 / 193 events/s, 0 failures
scaletest_dl_shard_0 peak / mean 16 / 15.8
scaletest_dl_shard_1 peak / mean 11 / 10.5
Master DB peak 1
Tenants caught up 25 / 25
Placement violations 0
Per-DB gate (≤ 16) PASS

Per-shard peaks sit at the single-DB governor plateau (12–14 baseline from the #494 measurement record; 16 here with 4 appender writers steering into 2 DBs), i.e. connections scale O(databases), not O(agents) — 50 agents produced a summed peak of 27, not 50+.

Full-scale rerun for the epic record: --databases 4 --tenants 100 --projections 2 --duration-seconds 120 --max-connections 16.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XNfeNz73Q3EdiTgSeDbo96

--databases N pools the tenants across N scaletest_dl_shard_* databases
via MultiTenantedWithShardedDatabases (explicit round-robin placement,
one daemon per shard). ShardConnectionSampler groups pg_stat_activity by
datname so the --max-connections gate is enforced PER DATABASE, plus
per-tenant catch-up verification on every shard and a database-affine
placement check (per-tenant sequence in exactly the home shard).

Local-scale result (25 tenants x 2 shards x 2 projections, 60s):
shard peaks 16/11, all 25 tenants caught up, zero placement violations.
Single-database path (--databases 1, the default) unchanged.

Addresses #4882

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XNfeNz73Q3EdiTgSeDbo96
@jeremydmiller
jeremydmiller force-pushed the feat/4882-sharded-daemonload branch from f8d8f7a to b76029b Compare July 7, 2026 19:36
@jeremydmiller
jeremydmiller merged commit 0f09e00 into master Jul 7, 2026
9 checks passed
@jeremydmiller
jeremydmiller deleted the feat/4882-sharded-daemonload branch July 7, 2026 20:10
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.

Marten.ScaleTesting: daemonload over pooled sharded databases — gate connections at O(databases) (epic jasperfx#486 WS6)

1 participant