Skip to content

infra(relay): raise asia-east2 cell pools to 16 and record the measured connection ceiling - #21163

Merged
Jinwoo-H merged 5 commits into
mainfrom
relay-asia-pool-fence
Sep 17, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
relay-asia-pool-fence

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

ELI5

People in Asia wait about four seconds to connect. Three of our servers live in Hong Kong, but the database they have to talk to lives in Iowa. Every question they ask takes a fifth of a second just to travel there and back, and each server only has ten phone lines to Iowa. The lines are all busy, so everyone queues.

This gives those three servers sixteen lines instead of ten. It also fixes a tally that claimed the database allowed 400 connections when it actually allows 500, which is what made the extra lines look unaffordable.

What Changed

Asia cell pools, 10 -> 16. In cloud/infra/terraform/environments/production.tfvars, production-gce-c27, c28, and c29 in asia-east2 get database_pool_max = 16. Every other cell stays at 10.

The recorded connection ceiling, 400 -> 500. In cloud/dev/contracts/production-cloud-sql-app-consumers.json, maxConnections and its source note. SHOW max_connections on the live instance returns 500, measured 2026-09-16. The old value was described as the tier default, and it is a tier default since no max_connections flag is set in either environment, but it was never checked against the instance.

The relay_gce_fenced_cells list is reflowed to one entry per line with a comment. No cell is added or removed here; the reflow is so that #21166, which does add two, reads as two added lines rather than a rewritten one.

The budget test repins to the figures that follow: cells 248, a usable ceiling of 490, and an operating maximum of 403.

Before and after, as a user experiences it: an Asia client's accept currently measures a p95 near 4 s against 222-646 ms in us-central1, because its cell's connection pool is queueing. Queueing theory on the measured service time puts the wait at 382 ms today and 1.8 ms at a pool of 16. Nothing changes for us-central1 users.

Why

The mechanism is round-trip time, not query cost. The renewal query that dominates the profile finishes in 64-256 microseconds server-side with zero disk reads. What holds a pool slot is the 176 ms trip to Iowa, multiplied by the 5-6 round trips a transaction makes. Measured service time per slot is ~390 ms in Asia against 22-115 ms in us-central1, which puts pool utilization at 0.92 — squarely in the queueing knee, where small load increases produce large waits.

Alternatives considered and rejected:

  • A read replica. There is none, and one would not help. Renewal takes three row locks and two updates in the same statement as the read, so there is no splittable read prefix.
  • Rewriting the query. Profiled: it is already a single statement, the locks are uncontended, and the materialization hint is a no-op. The 176 ms is structural.
  • Raising capacity_requests or connection_hard_cap. capacity_requests is a placement budget; raising it sends more work to a starved cell. connection_hard_cap accepts only 600, 1000, or 3000, and Asia is already at 3000.
  • A pool of 32 instead of 16. 32 is sized for a cell filled to its own hard cap, which is 2.37x today's load, and it peaks at 274 backends against a monitoring freeze threshold of 250. Shipping it would mean first recalibrating the instrument that tells you the change went wrong. 16 peaks at 226 and every threshold holds.

Why the ceiling correction is in this PR

On main the budget model sat at 385 against a usable ceiling of 390. Five connections of margin. Adding 18 takes it to 403 and fails the gate by 13 — against a ceiling that nobody had ever compared to the instance.

Correcting only that one number is a narrow, independently defensible fix: the contract claimed a tier default it had not verified, and the instance reports 500. With the measured ceiling the usable figure is 490 and this PR's 403 clears it by 87.

The alternative was to lower a pool or shrink the reserve until 390 accommodated the change, which would have made a real capacity signal quieter instead of more accurate.

Linked Issue

Fixes #

Visual Proof

N/A — infrastructure configuration and a data contract. There is no user interface surface.

Testing

Run from cloud/, with Terraform 1.15.8 locally to match the terraform_version: 1.15.8 pin in the workflows.

Gate Result
terraform fmt -check -recursive pass
terraform init -backend=false then terraform validate pass
pnpm -r test 941 pass, 108 skipped, 0 fail
Main node --test script list 596 pass, 0 fail
pretest script list 156 pass, 0 fail

No Terraform apply was run and no remote state was touched. init used -backend=false.

The arithmetic:

Term main This PR
Relay cells 230 248
Relay directors 15 15
Auth 20 20
API 50 50
Configured total 315 333
Rollout overlap 65 65
Admin allowance 5 5
Operating maximum 385 403
max_connections 400 500
Usable ceiling after a 10 reserve 390 490
Headroom +5 +87
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

The auth figure in that contract is still wrong, deliberately

The same file records auth at 2 instances. Production has run auth_max_instances = 20 since 2026-09-04, when a cap of 2 starved desktop token refresh with hours of 429s. This PR does not touch it.

#21165 corrects it, and when it lands this budget goes red. With auth at its real 20 instances the operating maximum is 715 against a usable ceiling of 490, of which auth is 415: 200 configured plus a 215 modelled rollout overlap. That overshoot exists today on main, hidden behind the stale figure. It is not caused by this PR and it is not closed by it — relay cells are 248 of the 715, and no relay-side change closes a 225-connection gap. Closing it is an auth sizing decision; #21165 lays out the options and what each one costs.

So read this PR's green gate as "correct against the numbers currently recorded", not as "the shared instance has room". Those become the same statement only after auth is resized.

Scope

This PR was originally three changes. The full contract correction moved to #21165 because the auth figure turns the gate red for reasons unrelated to Asia. The c4/c5 fence entries moved to #21166 because Terraform reads MIG target size straight from relay_gce_fenced_cells with no lifecycle ignore, so a fence entry on main is a standing resize instruction that any apply reaching those cells may execute without the documented drain and attestation. Those entries belong in a PR merged immediately before the fence run, not carried along by a pool change.

Note on the comment style

The three pool comments are trailing rather than on their own line. A standalone comment splits terraform fmt's alignment group and reflows seven unrelated attribute lines per cell, which would triple the diff for no gain.

Related

All three touch cloud/dev/scripts/relay-cloud-sql-connection-budget.test.mjs and will conflict textually. The conflicts are the pinned figures, a few lines each.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no identity, permission, or trust boundary changes. Cross-platform: Terraform, JSON, and a Node test file, no platform-dependent behavior. Remote SSH and Mobile: unaffected; the push gateway runs on its own instance and is not in this budget. Backwards compatibility: database_pool_max is an existing per-cell field with a default of 10; raising three cells changes no wire format or client contract. Performance: the intended effect is lower connection-accept latency for Asia clients; judge it on clientAcceptTotalMsP95 per region, not on waiter counts.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…cells

The three asia-east2 cells sit 176 ms from the Cloud SQL instance in
us-central1. Server-side statement time there is 0.2 ms, so a pool slot is
held by the round trip, not by the query. At a pool of 10 they measured
94-156 waiters and 2 s waits, and client accepts ran a ~4 s p95 against
222-646 ms in us-central1. Raising those three pools to 16 is the agreed
first step; every other cell stays at 10.

c4 and c5 join the committed fence set. Both are existing-only capacity the
admission selector can never place on again, they carried ~1 connection each
on 40-day-old images, and each still holds 10 Postgres connections. The fence
set is the prerequisite the fence-source workflow confirms before it drains
and attests a cell; it is not itself the resize.

c17 and c18 are not fenced here. They are migration-only, and the runbook
requires retire-migration-cell to move a migration-only cell to existing-only
through a generation-bound selector CAS before it can be fenced. Terraform
cannot express that step.

The Cloud SQL consumer contract carried two stale numbers: auth at 2 instances
when production has run a cap of 20 since 2026-09-04, and a 400-connection
ceiling when the live instance reports 500. Both are corrected, and the budget
now asserts its headroom in two named gates instead of one aggregate boolean.
Those gates fail: auth alone accounts for 200 configured connections and a
215-connection rollout overlap, so the operating maximum is 713 against a
usable ceiling of 490. Nothing here caused that, and no pool was lowered to
hide it.
The contract correction (auth at its real 20-instance cap, the measured
500-connection ceiling) makes the budget gate fail for reasons that have
nothing to do with asia pools or fenced cells, and it held this branch red.
It moves to its own branch where the failure is the subject.

production-cloud-sql-app-consumers.json returns to main unchanged. The budget
test keeps main's single gate and only repins the cell figure that this branch
genuinely moves: 230 -> 228, being +18 for three asia pools at 16 and -20 for
fencing c4 and c5. Against main's 400-connection model that leaves an operating
maximum of 383 under a usable ceiling of 390.
@Jinwoo-H Jinwoo-H changed the title infra(relay): raise asia-east2 cell pools to 16 and retire four idle cells infra(relay): raise asia-east2 cell pools to 16 and fence two idle cells Sep 17, 2026
Terraform now sets a cell's MIG target size directly from relay_gce_fenced_cells
(relay-gce-cells.tf); the lifecycle ignore that used to protect operational
target_size drift is gone. So a fence entry sitting on main ahead of its
fence-source run is a standing instruction that any apply reaching that cell may
execute without the documented drain and attestation. Keeping the entry in the
same merge as an unrelated pool change widens that blast radius for no reason.

The two entries move to their own branch, to be merged immediately before
fence-source runs for c4 and then c5. This branch keeps the multi-line reflow of
the list, which makes that later diff two added lines instead of a rewritten one.

The cell figure in the budget test follows: 230 + 18 for the three asia-east2
pools at 16, with no fenced-cell subtraction. That is 403 operating against a
usable ceiling of 390, so the headroom gate now fails by 13. It fails against a
ceiling of 400 that is itself wrong; the instance reports 500. See the PR body.
@Jinwoo-H Jinwoo-H changed the title infra(relay): raise asia-east2 cell pools to 16 and fence two idle cells infra(relay): raise asia-east2 cell pools to 16 Sep 17, 2026
The budget's usable ceiling came from maxConnections: 400, described as the
tier default. It is a tier default, since no max_connections flag is set, but
the instance does not report 400. SHOW max_connections on it returns 500,
measured 2026-09-16.

On main the model sat at 385 against a usable ceiling of 390, five connections
of margin, so raising the three asia-east2 pools by 18 failed the gate by 13
against a ceiling that was never checked. Against the measured one it is 403
against 490, clearing by 87.

Only the ceiling and its source note change here. auth stays recorded at 2
instances, which is also wrong; PR #21165 corrects it, and with the true auth
figure the budget is over by 225 for reasons that have nothing to do with these
pools.
@Jinwoo-H Jinwoo-H changed the title infra(relay): raise asia-east2 cell pools to 16 infra(relay): raise asia-east2 cell pools to 16 and record the measured connection ceiling Sep 17, 2026
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review September 17, 2026 06:00
@Jinwoo-H
Jinwoo-H merged commit 5947d6b into main Sep 17, 2026
24 checks passed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

This PR's two value changes desynchronize four production checks that still hardcode the old numbers. Raising the committed pool to 16 makes the Asia shape validators reject the cells, and the maxConnections bump makes the Asia topology workflow's live-ceiling assertion fail closed. pnpm -r test stays green because those tests use 10-valued fixtures and string-match the workflow — none evaluates the committed values. Both need to be fixed before this can merge.

Reviewed changes

  • Asia cell pools 10 → 16. production-gce-c27/c28/c29 in production.tfvars get database_pool_max = 16; the budget test is repinned to cells 248 / ceiling 490 / operating max 403 / headroom 87, all internally consistent with relay-cloud-sql-connection-budget.mjs.
  • Connection ceiling 400 → 500. production-cloud-sql-app-consumers.json now records the measured SHOW max_connections and updates the source note.
  • relay_gce_fenced_cells reflow only. Same six cells, one per line, plus a two-line comment; no cell added or removed.

ℹ️ Ceiling references outside the contract still say 400 / 385

The contract now records a 500-connection ceiling and the budget models a 403 operating maximum, but four operational references still cite the old figures. The alert documentation is the one with practical fallout: it describes the trip point as "80% of the 400-connection ceiling", while the threshold of 320 is now 64% of 500 — an on-call reader gets a wrong mental model of how much room is left.

Technical details
# Stale 400-connection ceiling references

## Affected sites
- `cloud/infra/terraform/relay-observability.tf:622` — alert `relay_cloud_sql_backends` documentation: "exceeded 80% of the 400-connection ceiling ... modeled 385-connection operating maximum". The condition threshold is 320 (`:607`), so the "80%" claim is no longer true.
- `cloud/docs/relay-incident-monitor.md:105` — "over 250 (62% of the verified 400-connection ceiling)"; the same sentence appears at `:216`.
- `cloud/apps/relay-ops/src/incident-monitor.ts:48` — comment "firing well before the verified 400-connection ceiling".

## Required outcome
- Every ceiling/percentage/operating-maximum reference reflects 500 / 403, or is reworded so it does not depend on the ceiling figure.
- Decide deliberately whether the `relay_cloud_sql_backends` threshold should track 80% of the raised ceiling (400) or stay at 320; either way the description must match the number.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

"apiInstances": 10,
"apiPoolMax": 5,
"maxConnections": 400,
"maxConnections": 500,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping maxConnections also changes the value the Asia topology workflow compares against the live instance. cloud-deploy-relay-asia-topology.yml:127 hardcodes live_max=400, and line 130 asserts test "${live_max}" = "${checked_max}". With no explicit max_connections flag — exactly the case this source note asserts — that assertion becomes test 400 = 500 and the workflow aborts before it plans the cells whose pool this PR raises.

Technical details
# `live_max=400` no longer matches the checked ceiling

## Affected sites
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:127` — hardcodes `live_max=400` in the `verified-shape-default` branch; `:121-122` repeats the claim in a comment.
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:107-108` — `checked_max` is `.maxConnections` from the budget report, now 500.
- `.github/workflows/cloud-deploy-relay-asia-topology.yml:110-130` — production-only comparison; the `else` branch is taken when `live_flag` is empty.
- `cloud/dev/scripts/relay-cloud-sql-connection-budget.mjs:138` — feeds `apps.maxConnections` through as `maxConnections`.

## Required outcome
- The workflow's verified-shape default and the contract must state the same number. If the live measurement of 500 is correct, update the `live_max` constant and the comment (and confirm the `db-custom-4-15360` + `POSTGRES_17` default really is 500); if 400 is the verified shape default, the contract change cannot stand as written.
- `cloud/dev/scripts/relay-asia-topology-workflow.test.mjs:74,77` only string-matches the workflow, so a test that evaluates the constant against the budget's `maxConnections` is what would have caught this.

boot_image = "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-stable-121-18867-528-21"
capacity_requests = 6000
database_pool_max = 10
database_pool_max = 16 # 176 ms from us-central1 Postgres saturates 10 (94-156 waiters).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising the committed pool to 16 desynchronizes the Asia cell-shape checks that still pin 10. prepare-relay-asia-topology-input.mjs:79 throws committed Asia cell differs from the reviewed topology; validate-relay-asia-topology-plan.mjs:85 rejects the startup script because it now carries ORCA_RELAY_DATABASE_POOL_MAX='16'; and prepare-relay-asia-director-cells.mjs:39 rejects the cell. The unit tests miss all three because they use 10-valued fixtures.

Technical details
# Asia shape validators still require `database_pool_max = 10`

## Affected sites
- `cloud/dev/scripts/prepare-relay-asia-topology-input.mjs:79` — expected shape pins `database_pool_max: 10`; the canonical equality check at `:90-95` then throws. Invoked from `cloud-deploy-relay-asia-topology.yml:187` with `--existing-json` built from `.variables.relay_gce_cells.value` (`:182-186`), which is now 16.
- `cloud/dev/scripts/validate-relay-asia-topology-plan.mjs:85` — `startupValue(script, 'ORCA_RELAY_DATABASE_POOL_MAX') !== '10'`; `cloud/infra/terraform/relay-gce-cells.tf:231` sets `include_database_pool_max` true for any non-`us-central1` cell, so the asia startup script emits `16`. Throws `does not have the reviewed Asia cell shape`. Invoked at `cloud-deploy-relay-asia-topology.yml:192` and `:227`.
- `cloud/dev/scripts/prepare-relay-asia-director-cells.mjs:39` — `cell.database_pool_max !== 10`; the topology comes from `terraform output relay_gce_cell_deployments` (`cloud/infra/terraform/outputs.tf:174`). Invoked at `cloud-operate-relay-asia-admission.yml:454`.

## Required outcome
- Each check accepts the reviewed pool for the environment it validates and rejects drift from it.
- These scripts are shared with staging (`validate-relay-asia-topology-plan.mjs`'s `CELL_SHAPES`, `prepare-relay-asia-topology-input.mjs`'s `SHAPES`), whose asia cell stays at 10 — do not simply flip the constant to 16.
- Update the fixtures in `prepare-relay-asia-topology-input.test.mjs`, `validate-relay-asia-topology-plan.test.mjs`, and `prepare-relay-asia-director-cells.test.mjs` so the production shape exercises the committed value.

ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…ed connection ceiling (stablyai#21163)

* infra(relay): raise asia-east2 cell pools to 16 and retire four idle cells

The three asia-east2 cells sit 176 ms from the Cloud SQL instance in
us-central1. Server-side statement time there is 0.2 ms, so a pool slot is
held by the round trip, not by the query. At a pool of 10 they measured
94-156 waiters and 2 s waits, and client accepts ran a ~4 s p95 against
222-646 ms in us-central1. Raising those three pools to 16 is the agreed
first step; every other cell stays at 10.

c4 and c5 join the committed fence set. Both are existing-only capacity the
admission selector can never place on again, they carried ~1 connection each
on 40-day-old images, and each still holds 10 Postgres connections. The fence
set is the prerequisite the fence-source workflow confirms before it drains
and attests a cell; it is not itself the resize.

c17 and c18 are not fenced here. They are migration-only, and the runbook
requires retire-migration-cell to move a migration-only cell to existing-only
through a generation-bound selector CAS before it can be fenced. Terraform
cannot express that step.

The Cloud SQL consumer contract carried two stale numbers: auth at 2 instances
when production has run a cap of 20 since 2026-09-04, and a 400-connection
ceiling when the live instance reports 500. Both are corrected, and the budget
now asserts its headroom in two named gates instead of one aggregate boolean.
Those gates fail: auth alone accounts for 200 configured connections and a
215-connection rollout overlap, so the operating maximum is 713 against a
usable ceiling of 490. Nothing here caused that, and no pool was lowered to
hide it.

* infra(relay): move the Cloud SQL contract correction out of this branch

The contract correction (auth at its real 20-instance cap, the measured
500-connection ceiling) makes the budget gate fail for reasons that have
nothing to do with asia pools or fenced cells, and it held this branch red.
It moves to its own branch where the failure is the subject.

production-cloud-sql-app-consumers.json returns to main unchanged. The budget
test keeps main's single gate and only repins the cell figure that this branch
genuinely moves: 230 -> 228, being +18 for three asia pools at 16 and -20 for
fencing c4 and c5. Against main's 400-connection model that leaves an operating
maximum of 383 under a usable ceiling of 390.

* infra(relay): move the c4/c5 fence entries out of this branch

Terraform now sets a cell's MIG target size directly from relay_gce_fenced_cells
(relay-gce-cells.tf); the lifecycle ignore that used to protect operational
target_size drift is gone. So a fence entry sitting on main ahead of its
fence-source run is a standing instruction that any apply reaching that cell may
execute without the documented drain and attestation. Keeping the entry in the
same merge as an unrelated pool change widens that blast radius for no reason.

The two entries move to their own branch, to be merged immediately before
fence-source runs for c4 and then c5. This branch keeps the multi-line reflow of
the list, which makes that later diff two added lines instead of a rewritten one.

The cell figure in the budget test follows: 230 + 18 for the three asia-east2
pools at 16, with no fenced-cell subtraction. That is 403 operating against a
usable ceiling of 390, so the headroom gate now fails by 13. It fails against a
ceiling of 400 that is itself wrong; the instance reports 500. See the PR body.

* infra(cloud-sql): record the measured 500-connection ceiling

The budget's usable ceiling came from maxConnections: 400, described as the
tier default. It is a tier default, since no max_connections flag is set, but
the instance does not report 400. SHOW max_connections on it returns 500,
measured 2026-09-16.

On main the model sat at 385 against a usable ceiling of 390, five connections
of margin, so raising the three asia-east2 pools by 18 failed the gate by 13
against a ceiling that was never checked. Against the measured one it is 403
against 490, clearing by 87.

Only the ceiling and its source note change here. auth stays recorded at 2
instances, which is also wrong; PR stablyai#21165 corrects it, and with the true auth
figure the budget is over by 225 for reasons that have nothing to do with these
pools.

* test(cloud): state the cell pool arithmetic literally in the budget pin comment
Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
…d 500-connection default (#22386)

The topology workflow's Cloud SQL gate carried a hard-coded 400 for the
instance's tier default while the consumer contract records the value
measured on the live instance (SHOW max_connections = 500, 2026-09-16,
#21163). The gate compares the two and the first production plan run
(35815654836) failed silently on that mismatch before Terraform ran.

The verified default now lives beside the tier and version it is verified
for, as VERIFIED_DEFAULT_MAX_CONNECTIONS, so the contract and the workflow
are two independent records of the same measurement and the gate keeps
its cross-check. The test pins the new source and forbids a bare literal.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
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