feat: implement dynamic concurrency control for SCENE_VLM
- Add dynamic_concurrency module with DynamicSemaphore, SystemMonitor, VlmMonitor, AutoScaler - Replace static SCENE_VLM_SEM with dynamic version (max concurrency: 3) - Add AutoScaler background task for automatic concurrency adjustment - Configured for M5Max48 (48GB): thresholds at 38GB/41GB - Expected processing time: 23-28 days for 10000 files Related: Phase 1 implementation after Phase 0 TKG fix verification
This commit is contained in:
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::Semaphore;
|
||||
use crate::core::dynamic_concurrency::{DynamicSemaphore, SystemMonitor, VlmMonitor, AutoScaler};
|
||||
use tokio::time::sleep;
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
@@ -30,7 +31,10 @@ static FACE_TRACE_INFLIGHT: LazyLock<tokio::sync::Mutex<std::collections::HashSe
|
||||
/// loads frames + calls the multimodal LLM; without a bound, dispatching many files
|
||||
/// in parallel would exhaust memory. One at a time mirrors the previous inline
|
||||
/// (sequential) behavior without blocking the worker poll loop.
|
||||
static SCENE_VLM_SEM: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1));
|
||||
static SCENE_VLM_SEM: LazyLock<Arc<DynamicSemaphore>> = LazyLock::new(|| Arc::new(DynamicSemaphore::new(1, 3, 1)));
|
||||
|
||||
/// Global VLM monitor for tracking response times
|
||||
static VLM_MONITOR: LazyLock<Arc<VlmMonitor>> = LazyLock::new(|| Arc::new(VlmMonitor::new()));
|
||||
|
||||
/// Tracks uuids with a Scene VLM task currently spawned (or queued for a permit).
|
||||
/// Prevents the per-poll loop from spawning duplicate tasks before `scenes.json`
|
||||
@@ -4866,3 +4870,19 @@ mod tests {
|
||||
assert!(stage_dependencies(ProcessorType::Cut).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
/// Start the AutoScaler background task for dynamic SCENE_VLM concurrency
|
||||
pub fn start_autoscaler() {
|
||||
let auto_scaler = Arc::new(AutoScaler::new(
|
||||
SCENE_VLM_SEM.clone(),
|
||||
Arc::new(SystemMonitor::new(48)), // M5Max48
|
||||
VLM_MONITOR.clone(),
|
||||
Duration::from_secs(30),
|
||||
));
|
||||
|
||||
tokio::spawn(async move {
|
||||
auto_scaler.run().await;
|
||||
});
|
||||
|
||||
info!("[AutoScaler] Started dynamic concurrency controller for SCENE_VLM");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user