Skip to content

Tune executor pool sizing based on 48h production monitoring #7376

Description

@beastoin

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:

  1. Little's Law baseline: workers >= arrival_rate × avg_service_time
  2. Add 25-50% headroom for Cloud Run burst traffic
  3. Deliberate throttles on rate-limited downstream pools (llm, stripe)
  4. 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:

  1. executor_pool_health log entries — are postprocess/storage queues draining?
  2. Cloud Run instance count — should decrease (less queue memory pressure)
  3. 202 response latency — should improve (storage unblocked)
  4. LLM/DB pool utilization — watch for bottleneck shift
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions