Skip to content

Give the critical Postgres pool room for slow WAL flushes - #312

Merged
iamwavecut merged 1 commit into
mainfrom
fix/critical-postgres-pool-headroom
Dec 1, 2026
Merged

iamwavecut merged 1 commit into
mainfrom
fix/critical-postgres-pool-headroom

Conversation

@iamwavecut

Copy link
Copy Markdown
Owner

Problem

Inbox transitions (claim, state checkpoint, complete), outbox receipts, and update materialization share the critical Postgres pool. Each of these operations keeps its connection until the WAL flush of its commit returns.

During a production incident on 2026-12-01, storage write latency rose about tenfold while the I/O volume stayed the same:

  • The critical pool has only 8 slots. Inbox claims, outbox receipts and materializer flushes hit the 3 s acquire timeout (pool timed out).
  • The durable consumer processed updates more slowly than they arrived at peak traffic, and the inbox wait reached about 10 minutes.
  • Updates older than the 5 min stale cutoff only reached history, so the bot did not answer them.

Change

  • POSTGRES_CRITICAL_MAX_CONNECTIONS: 8 → 16.
  • The durable consumer cap stays at three workers per critical slot, so it changes from 24 to 48. The per-CPU default limits it to 32 workers on an 8-CPU host (the old limit was 24).
  • The general pool keeps 42 slots. The total is 58, below max_connections = 100.

Verification

  • cargo fmt --all -- --check
  • cargo test -p openplotva-storage postgres_capacity
  • cargo test -p openplotva-app durable_update_consumer
  • cargo clippy --workspace --all-targets -- -D warnings

Inbox transitions, outbox receipts and update materialization share the
critical pool, and each holds its slot until the WAL flush returns. When
storage latency rose tenfold, eight slots starved inbox claims and outbox
receipts (3 s acquire timeouts), the durable consumer drained slower than
updates arrived, and messages aged past the 5 min stale cutoff.

Raise the critical pool to 16 slots. The durable consumer cap follows at
three workers per slot, so the 8-CPU host runs 32 inbox workers instead
of 24. The general pool keeps its 42 slots; 58 in total stays well under
max_connections = 100.
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Messages
📖 Danger checked 2 changed file(s).

Generated by 🚫 dangerJS against 6a7afa3

@iamwavecut
iamwavecut merged commit 13b17f2 into main Dec 1, 2026
12 checks passed
@iamwavecut
iamwavecut deleted the fix/critical-postgres-pool-headroom branch December 1, 2026 19:07
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