fix: 解决AI视频分类并发瓶颈问题
- 移除VideoClassificationService中共享的GeminiService实例 - 改为在classify_video_with_gemini方法中为每个任务创建独立的GeminiService - 解决Arc<Mutex<GeminiService>>导致的串行处理瓶颈 - 实现真正的并发处理,提升AI分类性能 修复前:所有worker共享一个GeminiService实例,导致串行等待 修复后:每个worker使用独立的GeminiService实例,实现真正并发
This commit is contained in:
parent
24d32825cd
commit
66f50a80c6
|
|
@ -8,7 +8,6 @@ use crate::infrastructure::file_system::FileSystemService;
|
|||
use anyhow::{Result, anyhow};
|
||||
use std::sync::Arc;
|
||||
use std::path::Path;
|
||||
use tokio::sync::Mutex;
|
||||
use serde_json;
|
||||
|
||||
/// AI视频分类业务服务
|
||||
|
|
@ -17,7 +16,7 @@ pub struct VideoClassificationService {
|
|||
video_repo: Arc<VideoClassificationRepository>,
|
||||
ai_classification_repo: Arc<AiClassificationRepository>,
|
||||
material_repo: Arc<MaterialRepository>,
|
||||
gemini_service: Arc<Mutex<GeminiService>>,
|
||||
gemini_config: Option<GeminiConfig>,
|
||||
}
|
||||
|
||||
impl VideoClassificationService {
|
||||
|
|
@ -28,13 +27,11 @@ impl VideoClassificationService {
|
|||
material_repo: Arc<MaterialRepository>,
|
||||
gemini_config: Option<GeminiConfig>,
|
||||
) -> Self {
|
||||
let gemini_service = Arc::new(Mutex::new(GeminiService::new(gemini_config)));
|
||||
|
||||
Self {
|
||||
video_repo,
|
||||
ai_classification_repo,
|
||||
material_repo,
|
||||
gemini_service,
|
||||
gemini_config,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +236,8 @@ impl VideoClassificationService {
|
|||
|
||||
/// 使用Gemini进行视频分类
|
||||
async fn classify_video_with_gemini(&self, task: &mut VideoClassificationTask, prompt: &str) -> Result<VideoClassificationRecord> {
|
||||
let mut gemini_service = self.gemini_service.lock().await;
|
||||
// 为每个任务创建独立的GeminiService实例,避免并发瓶颈
|
||||
let mut gemini_service = GeminiService::new(self.gemini_config.clone());
|
||||
|
||||
// 调用Gemini API进行分类
|
||||
let (file_uri, raw_response) = gemini_service.classify_video(&task.video_file_path, prompt).await?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue