Skip to content

feat: add BatchWorkpool for high-throughput task processing - #167

Open
sethconvex wants to merge 34 commits into
mainfrom
feat/pooled-execution-mode
Open

sethconvex wants to merge 34 commits into
mainfrom
feat/pooled-execution-mode

Conversation

@sethconvex

@sethconvex sethconvex commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds BatchWorkpool, a new execution mode where a small number of long-lived executor actions each run many task handlers concurrently. This eliminates the 1-action-per-task overhead of standard mode and enables much higher effective concurrency.

Key design decisions

  • Slot-based executor partitioning: Each task is assigned a random slot (0..maxWorkers-1) on enqueue. Each executor only claims tasks from its slot, eliminating OCC conflicts on the shared pending index — validated with zero OCC errors at 90K tasks.
  • Two-step claiming: Executors read pending task IDs via a query, then atomically claim them via a mutation with ownership verification, preventing stale executors from interfering.
  • Memory back-pressure: Executors pause claiming when V8 heap usage exceeds 70%, preventing OOM crashes on large batches.
  • Self-healing watchdog: A periodic mutation detects missing executors and restarts them, recovering from crashes and redeploys without manual intervention.
  • Claim ownership verification: complete, fail, and release mutations verify the calling executor still owns the task, preventing duplicate completions from stale executors.

What's included

  • src/client/batch.ts — BatchWorkpool class with action(), executor(), enqueue(), enqueueBatch(), enqueueByHandle()
  • src/component/batch.ts — Component-side mutations: enqueue, claim, complete, fail, release, executor lifecycle
  • src/component/schema.ts — batchTasks table with slot-partitioned indexes, batchConfig singleton
  • src/client/batch.test.ts — 100+ client-side unit tests (executor loop, retry, backoff, memory pressure)
  • src/component/batch.test.ts — 100+ component-side unit tests (claim ownership, slot isolation, edge cases)
  • example/ — Full comparison app with standard vs batch modes, stress test handlers
  • README.md — BatchWorkpool documentation and usage guide
  • BATCH_DESIGN_ANALYSIS.md — Detailed architecture rationale

Benchmarks: Standard vs Batch mode

Head-to-head comparison on the same Convex dev deployment. Each task runs a 2-second simulated handler (slowWork).

Mode Tasks Config Time Speedup
Standard 1K maxParallelism=100 42s 1x
Batch 1K 5 workers × 1000 concurrency 7s 6x
Standard 10K maxParallelism=100 556s (~9.3 min) 1x
Batch 10K 5 workers × 1000 concurrency 20s 28x

Standard mode processes ~100 tasks every ~2s (limited by maxParallelism and per-action scheduling overhead). Batch mode runs all tasks concurrently across 5 long-lived executors, completing 1K tasks in a single 2s cycle and 10K tasks in ~4 cycles.

Additional stress tests (batch mode only)

Test Tasks Handler delay Workers Time OCC errors
echo 10K 0ms 5 19s 0
slowWork 20K 2s 5 70s 0
slowWork 30K 2s 5 494s 0
simulatedWork 90K 200ms 5 527s 0

Zero OCC errors across all test configurations, validating the slot-based executor partitioning design.

Test plan

  • 217 unit tests pass (npm test)
  • TypeScript builds clean (npm run build)
  • Head-to-head benchmark: 6-28x faster than standard mode
  • Stress tested on live Convex deployment up to 90K tasks
  • Zero OCC errors across all test configurations
  • Verified self-healing after executor restarts

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Batch Execution Mode with BatchWorkpool for high-throughput task processing with memory-aware back-pressure and concurrent batch operations.
    • New batch configuration options for tuning worker concurrency and task retry behavior.
    • Extended API exports to support batch workpool types and operations.
  • Documentation

    • Added comprehensive Batch Execution Mode guide with design analysis covering architecture, tradeoffs, and performance considerations.

Latest branch benchmark (2026-02-14)

Additional apples-to-apples operational comparison on this branch:

Path Workload Time
Legacy standard path example:enqueueABunchOfActions × 67 (~2010 actions) 209s
New batch path test:runBatch (count=2000, mock translation enabled) 44s

Derived from this run:

  • Absolute delta: 165s faster
  • Speedup: 4.75x
  • Percent faster: 78.95%

Artifact: benchmark_results/standard_vs_batch_comparison_2026-02-14.txt

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

2 participants