fix(analysis): bound concurrent OCR inferences with a shared semaphore
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -443,11 +443,19 @@ async fn spawn_analysis_daemon(
|
||||
cfg.ocr_max_decode_pixels,
|
||||
)
|
||||
.context("build ocrs engine")?;
|
||||
// Cap concurrent CPU-bound OCR runs across all workers so a high
|
||||
// ANALYSIS_WORKERS can't oversubscribe the blocking pool.
|
||||
let cores = std::thread::available_parallelism()
|
||||
.map(|n| n.get())
|
||||
.unwrap_or(1);
|
||||
let permits =
|
||||
crate::analysis::ocr::ocr_concurrency_limit(cfg.workers, cores);
|
||||
let dispatcher = Arc::new(crate::analysis::ocr::OcrAnalyzeDispatcher {
|
||||
db: db.clone(),
|
||||
storage,
|
||||
engine: Arc::new(engine),
|
||||
max_image_bytes: cfg.max_image_bytes,
|
||||
ocr_permits: Arc::new(tokio::sync::Semaphore::new(permits)),
|
||||
});
|
||||
// In-process engine is always ready — no gate.
|
||||
(dispatcher, None)
|
||||
|
||||
Reference in New Issue
Block a user