Skip to content

fix(backend): tune executor pool sizing from 48h production monitoring - #7378

Merged
beastoin merged 4 commits into
mainfrom
fix/executor-pool-sizing-7376
May 19, 2026
Merged

beastoin merged 4 commits into
mainfrom
fix/executor-pool-sizing-7376

Conversation

@beastoin

Copy link
Copy Markdown
Collaborator

Summary

Closes #7376

Tunes executor thread pool sizes based on 48h production monitoring data collected by @mon after the bulkhead architecture deploy (PR #7343).

  • postprocess: 8 → 24 workers (CRITICAL — queue grew unboundedly to 1,239 tasks in 8h)
  • storage: 32 → 64 workers (WARNING — re-saturated within 1h of previous bump, queue peaks at 896)
  • db: 16 → 24 workers (proportional — absorb increased Firestore pressure from bigger postprocess/storage)
  • llm: 4 → 6 workers (proportional — postprocess expansion will feed more LLM work)
  • sync: 12 → 16 workers (ELEVATED — 97% util with no headroom)
  • critical: 8 → 8 (unchanged — auth gates, must stay isolated)
  • stripe: 4 → 4 (unchanged — deliberate API throttle)

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) and stripe_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 updated
  • test_async_http_infrastructure.py — pool sizing assertions updated
  • Post-deploy: monitor executor_pool_health logs for 4h — verify postprocess/storage queues drain
  • Post-deploy: verify Cloud Run instance count decreases (less queue memory pressure)
  • Post-deploy: watch db/llm pool utilization for bottleneck shift

🤖 Generated with Claude Code

@beastoin
beastoin merged commit aa3d531 into main May 19, 2026
3 checks passed
@beastoin

Copy link
Copy Markdown
Collaborator Author

lgtm

@beastoin
beastoin deleted the fix/executor-pool-sizing-7376 branch May 19, 2026 07:27
@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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.

  • executors.py: Five pools resized; critical_executor and stripe_executor are deliberately unchanged. Total managed threads grow from 84 to 146.
  • Tests: test_sync_v2.py and test_async_http_infrastructure.py updated; the infrastructure test also inadvertently fixes a pre-existing stale assertion (was checking storage == 16 while the code had already moved to 32).

Confidence Score: 4/5

Safe 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

Filename Overview
backend/utils/executors.py Thread pool sizes bumped (db 16→24, llm 4→6, sync 12→16, postprocess 8→24, storage 32→64); implementation and module-level exports are correct and consistent.
backend/CLAUDE.md Pool-assignment documentation updated to match new worker counts; all seven executors are correctly documented.
backend/tests/unit/test_sync_v2.py Worker-count assertions updated, but the source-level string check for max_workers=24 no longer uniquely identifies postprocess_executor now that db_executor shares the same count.
backend/tests/unit/test_async_http_infrastructure.py storage_executor test updated from 16→64; also fixes a pre-existing mismatch where the assertion was checking 16 while the actual value was already 32.

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)]
Loading

Reviews (1): Last reviewed commit: "test(backend): update sync_v2 pool sizin..." | Re-trigger Greptile

Comment on lines +2089 to +2091
assert 'max_workers=16' in source
assert 'postprocess_executor = MonitoredThreadPoolExecutor(' in source
assert 'max_workers=8' in source
assert 'max_workers=24' in source

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

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.

Tune executor pool sizing based on 48h production monitoring

1 participant