Repository navigation
Labels
p1Priority: Critical (score 22-29)
Description
Problem
After deploying the executor bulkhead architecture (PR #7343), 48h production monitoring reveals several pools are undersized:
- postprocess (8 workers) — CRITICAL: Queue grew unboundedly 0 → 1,239 in 8h. 100% utilization every hour. Tasks arrive faster than workers can drain.
- storage (32 workers) — WARNING: Bump from 16→32 (commit d9eb32c) gave ~1h relief then re-saturated. Queue peaks at 896.
- sync (12 workers) — ELEVATED: 97% utilization, max queue 17. No headroom.
- llm (4 workers) — OK but at risk: 75% util, zero queue — but postprocess expansion will feed it more work.
Decision Logic
Approach: Proportional Scaling with Downstream Protection
Why not just max out each pool?
Pools don't operate independently — postprocess fans out into db_executor (Firestore) and llm_executor (LLM API). Oversizing postprocess without matching db/llm capacity shifts the bottleneck downstream, increasing memory retention and task lifetime without improving real throughput.
Sizing method:
- Little's Law baseline:
workers >= arrival_rate × avg_service_time - Add 25-50% headroom for Cloud Run burst traffic
- Deliberate throttles on rate-limited downstream pools (llm, stripe)
- Proportional bumps: when expanding a producer pool, expand its consumer pools too
Per-Pool Rationale
| Pool | Current | New | Change | Rationale |
|---|---|---|---|---|
critical_executor |
8 | 8 | — | Auth gates. Must never starve. No change needed (not flagged in monitoring). |
db_executor |
16 | 24 | +50% | Absorb increased Firestore write pressure from 3x postprocess + 2x storage expansion. Ceiling ~32 before hot-doc contention becomes the bottleneck. |
storage_executor |
32 | 64 | +100% | Pure I/O-bound GCS work. Re-saturated within 1h at 32. Practical ceiling ~96 before audio buffer memory pressure. |
postprocess_executor |
8 | 24 | +200% | Queue growing unboundedly at 8. 24 gives 3x throughput without overwhelming downstream. Avoid jumping to 64+ — if 24 still grows monotonically, the fix is durable task queuing, not more threads. |
llm_executor |
4 | 6 | +50% | Currently healthy at 75%, but postprocess expansion will submit more LLM work. Keep deliberately small as API-rate-limit backpressure. Ceiling ~8. |
sync_executor |
12 | 16 | +33% | 97% util with bounded queue. Mixed VAD/STT pipeline has CPU-bound segments, so large thread jumps have diminishing returns. |
stripe_executor |
4 | 4 | — | External API, low volume. Deliberate throttle. |
Thread Count Impact
- Before: 84 total threads (8+16+4+4+12+8+32)
- After: 146 total threads (8+24+6+4+16+24+64)
- Delta: +62 threads (~74% increase)
- Memory overhead: ~3-6MB for idle thread stacks (negligible). Active thread memory depends on in-flight data.
- Expected benefit: Reduced queue memory pressure (draining 1,239+ queued tasks), fewer instance count spikes, lower 202 latency.
Monitoring Plan
After deploy, watch for 4h:
executor_pool_healthlog entries — are postprocess/storage queues draining?- Cloud Run instance count — should decrease (less queue memory pressure)
- 202 response latency — should improve (storage unblocked)
- LLM/DB pool utilization — watch for bottleneck shift
- Firestore error rate — watch for contention from db_executor expansion
If postprocess queue still grows at 24, next step is durable background processing (Cloud Tasks / Pub/Sub), not more threads.
References
- PR fix(backend): eliminate async event-loop blockers in FastAPI endpoints #7343 — executor bulkhead architecture (original)
- Commit d9eb32c — storage_executor bump 16→32
- Learnings [build] remove supabase env vars #81 — post-deploy instance count alert
Metadata
Metadata
Assignees
Labels
p1Priority: Critical (score 22-29)
Activity
fix(backend): tune executor pool sizing from 48h production monitoring (
fix(backend): tune executor pool sizing from 48h production monitoring (
docs(backend): update CLAUDE.md pool sizes to match new executor conf…
test(backend): update http infrastructure pool sizing assertions (Bas…
test(backend): update sync_v2 pool sizing assertions (BasedHardware#7376
fix(backend): bump storage_executor 64→96 workers — queue exceeds 300…
docs(backend): update CLAUDE.md storage pool size 64→96 (BasedHardwar…
test(backend): update storage pool sizing assertion 64→96 (BasedHardw…
test(backend): update sync_v2 storage pool assertion 64→96 (BasedHard…