Skip to content

feat(relay): make Redis pool size configurable, default 16 - #2521

Merged
tlongwell-block merged 1 commit into
mainfrom
eva/redis-pool-size
Jul 23, 2026
Merged

feat(relay): make Redis pool size configurable, default 16#2521
tlongwell-block merged 1 commit into
mainfrom
eva/redis-pool-size

Conversation

@tlongwell-block

Copy link
Copy Markdown
Collaborator

Why

bb-public relay pods started showing Redis pool waiters today (buzz_redis_pool_waiting peaked at 2, buzz_redis_pool_available min 1) at ~190 events/s — first waiters since launch day.

Root cause: we never configure the deadpool-redis pool size, so it uses deadpool's default of CPU_COUNT * 2. On a 2-vCPU relay pod that's 4 connections, shared by rate-limit checks, presence, pub/sub publishes, NIP-98 replay guard, and cache invalidation. Confirmed live: every bb-public pod reports buzz_redis_pool_max = 4.

What

  • New BUZZ_REDIS_POOL_SIZE env var (relay), default 16 when unset; zero/unparsable values fall back to the default.
  • Wired into the single shared pool built in main.rs (the only production pool construction; test-only pools untouched).
  • .env.example documents it.

Minimal by design: 16 per pod × 5 pods = 80 Redis connections vs ElastiCache's 65k ceiling — noise for the server, but 4× more headroom where the waiters showed up. No chart change needed; ops can tune per-deploy via env.

Testing

  • New config test: env override (32), zero → fallback, junk → fallback; defaults_are_valid asserts the 16 default.
  • cargo test -p buzz-relay: 735 passed, 1 failed — api::mesh_demo::tests::demo_join_forwarded_arm_round_trips_echo, which fails identically on clean origin/main at the same SHA (pre-existing, known flake).
  • cargo clippy -p buzz-relay --all-targets clean, cargo fmt clean.

Observability

Watch block.buzz_relay.buzz_redis_pool_max flip 4 → 16 on rollout, and buzz_redis_pool_waiting stay at 0.

deadpool-redis defaults its pool max to CPU_COUNT * 2, which on a
2-vCPU relay pod is only 4 connections shared by rate limiting,
presence, pub/sub publishes, and cache invalidation. bb-public pods
started showing pool waiters (buzz_redis_pool_waiting > 0,
buzz_redis_pool_max = 4) at ~190 events/s.

Raise the default to 16 and expose BUZZ_REDIS_POOL_SIZE for
per-deploy tuning. Zero or unparsable values fall back to the
default.

Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
@tlongwell-block
tlongwell-block requested a review from a team as a code owner July 23, 2026 14:17
@tlongwell-block
tlongwell-block merged commit bcc3e13 into main Jul 23, 2026
32 checks passed
@tlongwell-block
tlongwell-block deleted the eva/redis-pool-size branch July 23, 2026 14:55
yoamomonstruos added a commit that referenced this pull request Jul 23, 2026
…arch

* origin/main:
  Refine channel lifecycle settings (#2427)
  Fix avatar upload lifecycle edge cases (#2277)
  fix(observer): eager archive hydration on panel open + 200-frame pages (#2574)
  fix(cli): install rustls crypto provider to unbreak WSS publishes in release builds (#2590)
  feat(dev): add `just production` recipe targeting the production relay (#2572)
  chore: Omit the Model control when an optional-model harness has nothing to select (#2262)
  fix(ci): stop moving protected Sprig rolling tag (#2221)
  fix(media): sanitize animated image uploads (#2524)
  fix(desktop): populate team instructions when opening the edit team dialog (#2565)
  feat(desktop): add drag-to-reorder for community rail (#2549)
  fix(channels): strip leading hash prefixes from names (#2250)
  fix(desktop): allow skipping harness setup onboarding (#2360)
  Script cleanup
  feat(relay): make Redis pool size configurable, default 16 (#2521)

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	desktop/src-tauri/src/commands/profile.rs
tlongwell-block added a commit that referenced this pull request Jul 28, 2026
## Summary

- Raise the relay's Postgres pool cap from the `buzz-db` default of 20
to 50 per pool, and expose `BUZZ_DB_POOL_SIZE` for per-deploy tuning
- Applies to the writer pool and, when `READ_DATABASE_URL` is set, the
reader pool; zero/unparsable values fall back to the default
- The `buzz-db` library default is unchanged — only the relay opts into
the larger cap

## Why

During the 2026-07-27 18:40–19:05Z traffic burst on bb-public, per-pod
PG pools pinned at 20 fleet-wide and ~380 requests failed on the 3s
acquire timeout — membership checks, channel access lookups, and
historical queries returning errors to users. The database was nowhere
near a limit: Aurora (db.r8g.8xlarge, ~5,000 max connections) sat at 19%
CPU, 201 connections (~4% of capacity), commit latency flat at 0.01ms.

The 20-connection default was sized for "four relay pods against PG
max_connections=100" (the comment in `buzz-db` says exactly that).
Production now runs 12–15 pods against Aurora — the per-pod cap is the
binding constraint, not the DB.

Budget at the new default: 15 pods × (50 writer + 50 reader + 5 audit) ≈
1,575 potential connections, ~30% of Aurora's ceiling — and actual usage
stays demand-driven (`min_connections` stays 2, connections only open
under load).

Same shape as #2521 (`BUZZ_REDIS_POOL_SIZE`), which fixed the identical
class of ceiling on the Redis side.

## Testing

- `cargo test -p buzz-relay`: 762 passed, 1 failed — the lone red is
`api::mesh_demo::tests::demo_join_forwarded_arm_round_trips_echo`, the
known pre-existing flake; it fails identically on clean `main` at the
same SHA (verified via `git stash` / rerun)
- New test `db_pool_size_env_override_and_invalid_fallback` covers
override, zero, and unparsable fallback
- `defaults_are_valid` extended to pin the new default
- `cargo clippy -p buzz-relay --all-targets -- -D warnings` and `cargo
fmt --check` clean

Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz>
Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
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