Repository navigation
fix(backend): tune executor pool sizing from 48h production monitoring - #7378
Conversation
#7376) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ig (#7376) Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
lgtm |
Greptile SummaryThis PR tunes the six variable-size thread pool executors based on 48 hours of production monitoring data, roughly doubling the most-saturated pools (postprocess 8→24, storage 32→64) and proportionally scaling downstream ones (db, llm, sync). Documentation and all related tests are updated to match.
Confidence Score: 4/5Safe to merge; the changes are confined to integer constants and their test assertions, with no logic alterations. The core change is straightforward constant-bumping backed by monitoring data, and the documentation is kept in sync. The only issue is that the max_workers=24 source-string guard in test_sync_v2.py now passes trivially because two executors share that count, so a silent postprocess regression would go undetected by that assertion. backend/tests/unit/test_sync_v2.py — the worker-count assertion for postprocess_executor should be strengthened to a live attribute check. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Request] --> B{Route Type}
B -->|Auth gates| C[critical_executor\n8w — unchanged]
B -->|Sync pipeline| D[sync_executor\n12w → 16w]
B -->|Post-processing| E[postprocess_executor\n8w → 24w]
B -->|Stripe API| F[stripe_executor\n4w — unchanged]
D --> G[db_executor\n16w → 24w]
E --> G
E --> H[llm_executor\n4w → 6w]
E --> I[storage_executor\n32w → 64w]
G --> J[(Firestore / Redis)]
H --> K[LLM API]
I --> L[(GCS)]
Reviews (1): Last reviewed commit: "test(backend): update sync_v2 pool sizin..." | Re-trigger Greptile |
| assert 'max_workers=16' in source | ||
| assert 'postprocess_executor = MonitoredThreadPoolExecutor(' in source | ||
| assert 'max_workers=8' in source | ||
| assert 'max_workers=24' in source |
There was a problem hiding this comment.
Test assertion no longer uniquely pins postprocess to 24 workers
After this PR, both db_executor (24) and postprocess_executor (24) share the same max_workers value. The bare substring check 'max_workers=24' in source now passes as long as any executor has 24 workers — so if postprocess_executor is silently reverted to 8, this assertion still succeeds because db_executor keeps the string in the file. The guard that was supposed to prevent a postprocess regression now has a false positive. The storage_executor assertion on line 2094 uses a live attribute check (storage_executor._max_workers == 64) which is the correct pattern; the same approach should be applied to postprocess_executor and sync_executor.
Summary
Closes #7376
Tunes executor thread pool sizes based on 48h production monitoring data collected by @mon after the bulkhead architecture deploy (PR #7343).
Total threads: 84 → 146 (+74%). All I/O-bound, minimal CPU/memory impact.
Decision Logic
Sizing based on Codex consultation using Little's Law (
workers >= arrival_rate × avg_service_time) with 25-50% headroom for Cloud Run burst traffic. Key principle: proportional scaling with downstream protection — don't oversize postprocess without matching db/llm capacity, or the bottleneck just shifts downstream.Deliberate throttles kept on
llm_executor(API rate limit backpressure) andstripe_executor(external API). If postprocess queue still grows at 24, next step is durable background processing (Cloud Tasks), not more threads.Full decision rationale in #7376.
Test plan
test_executors.py— 24 tests pass (pool metrics, health logging, monitoring)test_sync_v2.py— executor worker count assertions updatedtest_async_http_infrastructure.py— pool sizing assertions updatedexecutor_pool_healthlogs for 4h — verify postprocess/storage queues drain🤖 Generated with Claude Code