Commit
feat: add ProcessPoolExecutor for parallel audio analysis
Commit details
Commit notes
Scaling improvements to Python Essentia service:
## ProcessPoolExecutor Architecture - Each analysis runs in a separate process (bypasses Python GIL) - Pool size = CPU cores - 1 (leave headroom for main process) - Workers are pre-initialized with Essentia algorithms on startup - Cross-process serialization via Pydantic model_dump()
## Parallel Batch Processing - /analyze/batch endpoint processes files concurrently - Semaphore-based concurrency control (configurable max_concurrent) - Maintains original file order in results - Graceful error handling per file
## Non-blocking Async - run_in_executor() ensures event loop isn't blocked - FastAPI can handle multiple concurrent requests - Single uvicorn worker (parallelism via ProcessPoolExecutor)
## New Endpoints - GET /stats - Pool status, worker count, CPU count
## Configuration - ESSENTIA_WORKERS - Number of analysis workers (default: cpu_count - 1) - max_concurrent query param for batch control
This matches the scaling pattern of the Bun worker's WorkerPool but uses multiprocessing (true parallelism) instead of worker threads.
Co-authored-by: armin.naimi <[email redacted]>
- Files changed
- 4
- Lines added
- +272
- Lines removed
- −48