Repository navigation
Closed
Labels
p1Priority: Critical (score 22-29)
Description
Problem
Backend (non-sync) storage_executor queue spikes to 738-844 at 96 workers while backend-sync stays stable at 173 max queue with identical pool sizing. The difference is caused by unbounded fan-out patterns in storage task submissions.
Evidence
Post-deploy monitoring (PR #7378, #7380) — storage pool at 96 workers:
| Service | Avg Queue | Max Queue | Status |
|---|---|---|---|
| backend-sync | 37.6 | 173 | Stable |
| backend | 350.8 | 844 | Worsening with traffic |
backend-sync queue is bounded; backend queue scales with traffic volume.
Root Cause: 3 Unbounded Fan-Out Patterns
1. Audio chunk downloads (utils/other/storage.py:764-767)
download_audio_chunks_and_merge()submits onestorage_executor.submit()per audio timestamp- 30-second audio = 30 parallel tasks per merge call
- No per-request concurrency limit
2. Audio precaching (routers/sync.py:209,308 + utils/other/storage.py:997)
_precache_all_parallel()and_cache_uncached_parallel()submit one task per audio file- Each file's merge triggers chunk downloads (pattern Client #1)
- Single precache request with 10 files × 30 chunks = 300+ tasks
3. Knowledge graph rebuild (utils/llm/knowledge_graph.py:263)
rebuild_knowledge_graph()submits one task per memory in user history- User with 1,000 memories = 1,000 concurrent storage tasks
- No batching or limit
Why Backend >> Backend-Sync
- backend-sync: mobile sync uploads use 60s batch accumulation (pusher), 3 tasks per batch flush. Predictable, bounded.
- backend: HTTP API serves on-demand audio downloads and precaching with per-chunk fan-out. One request can monopolize the pool.
Call Site Inventory
42 total storage_executor submission sites across 15 files:
routers/sync.py: 10 calls (precaching + cleanup)routers/apps.py: 7 calls (logo/thumbnail uploads)utils/other/storage.py: 4 calls (chunk download fan-out, merge upload, precache)routers/pusher.py: 3 calls (batch flush)routers/imports.py: 3 calls (ZIP processing, long-running import)utils/chat.py: 3 calls (voice message cleanup)routers/transcribe.py: 2 calls (speaker profile audio)utils/speaker_sample_migration.py: 4 calls- Others: 6 calls (knowledge_graph, notifications, postprocess, vad, speech_profile, speaker_embedding)
Affected Services
- backend (Cloud Run) — primary impact
- backend-sync (Cloud Run) — stable but same code paths exist
- backend-listen (GKE) — shares codebase
References
- PR fix(backend): tune executor pool sizing from 48h production monitoring #7378 — pool sizing tuning (postprocess/db/llm/sync resolved)
- PR fix(backend): bump storage_executor 64→96 — queue exceeds 300 threshold #7380 — storage bump 64→96 (backend-sync resolved, backend still saturating)
- Issue Tune executor pool sizing based on 48h production monitoring #7376 — executor pool sizing decision logic
Metadata
Metadata
Assignees
Labels
p1Priority: Critical (score 22-29)
Activity
beastoin commentedon May 19, 2026
Update: Mon's Production Traffic Analysis
The burst analysis reveals this is primarily a traffic volume + instance count problem, not just fan-out patterns.
Key Finding: Backend Instance Imbalance
Backend handles 160x more load per instance than backend-sync with identical pool sizing.
Top Storage-Heavy Endpoints (45-min window)
/v3/memoriesalone consumes ~44% of storage pool capacity (25 slow ops/sec at 1.7s avg, 96 workers can process ~56 ops/sec).Queue Pattern: Bursty, Not Monotonic
At 96 workers the queue recovers between bursts (hit 0 at 10:07, spiked to 844 at 10:57). This confirms 96 workers handle steady-state but not burst peaks. Background cron/batch contributes ~20 ops/min — negligible vs 3,300 req/min API traffic.
Visibility Gap
Only 1 of 3 backend instances reports executor_pool_health logs. The 844 max queue is from a single instance.
Updated Recommendations
The unbounded fan-out patterns (audio chunk downloads, precaching, KG rebuild) from the original issue remain valid as medium-term optimizations, but the primary driver is sustained API traffic volume on too few instances.
beastoin commentedon May 19, 2026
Correction: /v3/memories is NOT the storage queue driver
Previous analysis incorrectly attributed storage_executor saturation to
/v3/memories.GET /v3/memoriesdoes not usestorage_executorat all — it's a pure Firestore read (memories_db.get_memories) running ondb_executor. The 1.7s avg latency on memories is a symptom of overall instance overload, not a cause of storage queue buildup.Actual storage_executor load sources (code-traced)
Primary driver:
process_conversation→precache_conversation_audio(utils/conversations/process_conversation.py:820)Every completed conversation triggers
precache_conversation_audio(), which fans out intostorage_executor:storage_executor.submit(_cache_single, af)(storage.py:997)download_audio_chunks_and_merge()→ per-chunk fan-out (storage.py:764-767)process_conversationis called from 6 different entry points on backend:routers/pusher.py:134— pusher conversation processingrouters/transcribe.py:778,1749,2793— WebSocket session conversation timeoutsrouters/conversations.py:95,120— conversation create/reprocess APIrouters/developer.py:882,1047— developer API conversation creationrouters/integration.py:144— integration webhook processingrouters/sync.py:717,1022— sync pipeline conversation processingSecondary: direct audio download fan-out
routers/sync.py:374,386— on-demand audio merge for sync endpointutils/speaker_identification.py:391— speaker sample audio downloadTertiary: apps uploads, imports, speaker profile I/O
routers/apps.py— 7 call sites for logo/thumbnail GCS uploads (per-request, low volume)routers/imports.py:78— long-running import job holds storage thread >30srouters/transcribe.py:1779,1786— speaker profile audio reads (per-session)Why backend has 4x the storage load vs backend-sync
Both services run
process_conversation, but backend receives it from more entry points at higher volume:process_conversationfrom the sync routerWhat to fix
The root cause is unbounded fan-out in audio precaching, not endpoint latency or instance count. Each
precache_conversation_audiocall submits N×M tasks (files × chunks) to storage_executor with no per-request concurrency limit. Adding a per-call semaphore (e.g., max 16 concurrent chunk downloads per merge operation) would cap burst submissions without requiring more threads or instances.Instance scaling (3→5) would still help by distributing
process_conversationcalls across more instances, but won't fix the fundamental per-request fan-out pattern.fix(backend): add bounded fan-out for storage_executor submissions (#…
fix(backend): gate sync precache fan-out with _PRECACHE_FILE_SEM (#7387)
fix(backend): move KG rebuild from storage_executor to llm_executor (#…
fix(backend): use sync_executor for speaker ID audio merge parent (#7387
test(backend): add fan-out concurrency limit assertions (#7387)
test(backend): update KG migration tests for llm_executor (#7387)
test(backend): add test_storage_fanout_limits.py to test.sh (#7387)
docs(backend): update CLAUDE.md pool assignments for fan-out limits (#…
fix(backend): move notification fan-out from storage_executor to post…
test(backend): add behavioral sliding-window and notification fan-out…
fix(backend): add return_exceptions=True to bulk summary batching (#7387
test(backend): update notification migration tests for postprocess_ex…
test(backend): update webhook wiring test for postprocess_executor (#…
feat(backend): add duplicate merge tracking logs for audio precache (#…
feat(backend): pass caller context to audio merge for duplicate track…
refactor(backend): polish audio merge tracking logs (#7387)
fix(backend): downgrade high-frequency audio logs to DEBUG (#7387)
fix(backend): bound storage_executor fan-out with per-request semapho…
docs(backend): correct the webhook wiring docstring and failure-class…
fix(backend): give the daily-summary webhook a lifecycle owner (#12742)