docs: Deep Scan Queue clarification responses
Studio team confirmed: 1. Resource monitoring: cpu/ram/gpu only 2. Adjustment frequency: 3 seconds 3. Retry strategy: TBD (Phase 1 basic, Phase 3 advanced) 4. Frontend integration: Polling API + CLI + Redis access Phase 1 implementation plan finalized: - Database schema extension - Queue status API - Priority queue support - Basic retry logic - Resource monitoring foundation Timeline: Phase 1 (Oct 15), Phase 2 (Oct 22), Phase 3 (Oct 29) Status: Ready to start Phase 1 development
This commit is contained in:
@@ -0,0 +1,293 @@
|
||||
# Deep Scan Queue 澄清问题回复 - 2026-10-08
|
||||
|
||||
## Studio Team 回复
|
||||
|
||||
### 1. 资源监控范围
|
||||
**回复**: cpu/ram/gpu
|
||||
|
||||
**Core Team 确认**: ✅ 明确
|
||||
- 监控:CPU 使用率、内存使用率、GPU 使用率(如可用)
|
||||
- 不包含:外部服务(LLM、Qdrant、PostgreSQL)
|
||||
- 实现:系统级监控,跨平台兼容
|
||||
|
||||
### 2. 动态并发调整频率
|
||||
**回复**: 3秒
|
||||
|
||||
**Core Team 确认**: ✅ 明确
|
||||
- 每 3 秒检查资源使用率
|
||||
- 使用滑动窗口平均(过去 30 秒,10 个采样点)
|
||||
- 调整策略:
|
||||
- 资源使用 > 85%:减少并发(-1)
|
||||
- 资源使用 < 60%:增加并发(+1)
|
||||
- 调整间隔:至少 30 秒(避免频繁调整)
|
||||
|
||||
### 3. 重试策略
|
||||
**回复**: 待定
|
||||
|
||||
**Core Team 建议**:
|
||||
Phase 1 先实现基础重试(固定重试次数),Phase 3 再细化策略。
|
||||
|
||||
**默认策略**:
|
||||
- 重试次数:3 次
|
||||
- 重试延迟:指数退避(10s, 30s, 60s)
|
||||
- 失败后状态:标记为 FAILED,保留错误信息
|
||||
|
||||
### 4. 前端集成方式
|
||||
**回复**: 轮询api/cli/redis access
|
||||
|
||||
**Core Team 确认**: ✅ 明确
|
||||
- **主要方式**: 轮询 API
|
||||
- `GET /api/v1/queue/status`(每 2-3 秒)
|
||||
- **次要方式**: CLI(管理用途)
|
||||
- `momentry queue status`
|
||||
- `momentry queue pause`
|
||||
- **高级方式**: Redis 访问(可选)
|
||||
- 直接读取队列状态(适合性能敏感场景)
|
||||
- 键名: `momentry:queue:status`
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 实施计划(最终版)
|
||||
|
||||
### 目标
|
||||
基础队列功能,2-3 周交付
|
||||
|
||||
### 任务清单
|
||||
|
||||
#### 1. 数据库扩展(第 1-2 天)
|
||||
```sql
|
||||
-- 扩展 monitor_jobs 表
|
||||
ALTER TABLE monitor_jobs ADD COLUMN priority TEXT DEFAULT 'normal';
|
||||
ALTER TABLE monitor_jobs ADD COLUMN retry_count INTEGER DEFAULT 0;
|
||||
ALTER TABLE monitor_jobs ADD COLUMN max_retries INTEGER DEFAULT 3;
|
||||
ALTER TABLE monitor_jobs ADD COLUMN last_error TEXT;
|
||||
|
||||
-- 创建索引
|
||||
CREATE INDEX idx_monitor_jobs_priority ON monitor_jobs(priority DESC, created_at ASC);
|
||||
```
|
||||
|
||||
#### 2. 队列状态 API(第 3-4 天)
|
||||
```rust
|
||||
// GET /api/v1/queue/status
|
||||
pub struct QueueStatusResponse {
|
||||
pub active_count: u32,
|
||||
pub max_concurrent: u32,
|
||||
pub pending_count: u32,
|
||||
pub paused: bool,
|
||||
pub queue: Vec<QueueTask>,
|
||||
pub statistics: QueueStatistics,
|
||||
}
|
||||
|
||||
pub struct QueueTask {
|
||||
pub task_id: String,
|
||||
pub file_uuid: String,
|
||||
pub file_name: String,
|
||||
pub status: String, // pending, processing
|
||||
pub priority: String,
|
||||
pub progress: u32,
|
||||
pub queued_at: String,
|
||||
pub started_at: Option<String>,
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. Worker 优先级支持(第 5-7 天)
|
||||
```rust
|
||||
// Worker::poll_jobs 修改
|
||||
async fn poll_jobs(&self) -> Result<Vec<MonitorJob>> {
|
||||
// 按优先级排序
|
||||
let jobs = sqlx::query_as::<_, MonitorJob>(
|
||||
"SELECT * FROM monitor_jobs
|
||||
WHERE status = 'QUEUED'
|
||||
ORDER BY
|
||||
CASE priority
|
||||
WHEN 'high' THEN 1
|
||||
WHEN 'normal' THEN 2
|
||||
WHEN 'low' THEN 3
|
||||
END,
|
||||
created_at ASC
|
||||
LIMIT $1"
|
||||
)
|
||||
.bind(self.config.batch_size)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
Ok(jobs)
|
||||
}
|
||||
```
|
||||
|
||||
#### 4. 基本重试逻辑(第 8-10 天)
|
||||
```rust
|
||||
// Worker::handle_failed_job
|
||||
async fn handle_failed_job(&self, job: &MonitorJob, error: &str) -> Result<()> {
|
||||
let retry_count = job.retry_count + 1;
|
||||
|
||||
if retry_count < job.max_retries {
|
||||
// 重试
|
||||
let delay = 10 * (2_u64.pow(retry_count as u32)); // 10s, 20s, 40s
|
||||
tokio::time::sleep(Duration::from_secs(delay)).await;
|
||||
|
||||
self.db.retry_job(job.id, retry_count).await?;
|
||||
} else {
|
||||
// 标记失败
|
||||
self.db.update_job_status(job.id, MonitorJobStatus::Failed).await?;
|
||||
self.db.update_job_error(job.id, error).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
#### 5. 优先级调整 API(第 11-12 天)
|
||||
```rust
|
||||
// PUT /api/v1/queue/task/{task_id}/priority
|
||||
pub async fn update_task_priority(
|
||||
State(state): State<AppState>,
|
||||
Path(task_id): Path<String>,
|
||||
Json(req): Json<UpdatePriorityRequest>,
|
||||
) -> Result<Json<UpdatePriorityResponse>, AppError> {
|
||||
sqlx::query(
|
||||
"UPDATE monitor_jobs SET priority = $1 WHERE id = $2"
|
||||
)
|
||||
.bind(&req.priority)
|
||||
.bind(&task_id)
|
||||
.execute(state.db.pool())
|
||||
.await?;
|
||||
|
||||
Ok(Json(UpdatePriorityResponse {
|
||||
success: true,
|
||||
task_id,
|
||||
priority: req.priority,
|
||||
}))
|
||||
}
|
||||
```
|
||||
|
||||
#### 6. 资源监控基础(第 13-15 天)
|
||||
```rust
|
||||
pub struct ResourceMonitor {
|
||||
check_interval: Duration, // 3 秒
|
||||
window_size: usize, // 10 个采样点
|
||||
samples: VecDeque<ResourceSample>,
|
||||
}
|
||||
|
||||
pub struct ResourceSample {
|
||||
pub timestamp: Instant,
|
||||
pub cpu_usage: f64,
|
||||
pub memory_usage: f64,
|
||||
pub gpu_usage: Option<f64>,
|
||||
}
|
||||
|
||||
impl ResourceMonitor {
|
||||
pub fn suggest_concurrency(&self) -> u32 {
|
||||
let avg_cpu: f64 = self.samples.iter().map(|s| s.cpu_usage).sum::<f64>()
|
||||
/ self.samples.len() as f64;
|
||||
let avg_mem: f64 = self.samples.iter().map(|s| s.memory_usage).sum::<f64>()
|
||||
/ self.samples.len() as f64;
|
||||
|
||||
// 简化策略
|
||||
if avg_cpu > 85.0 || avg_mem > 85.0 {
|
||||
// 资源紧张,建议减少并发
|
||||
1
|
||||
} else if avg_cpu < 60.0 && avg_mem < 60.0 {
|
||||
// 资源充足,建议增加并发
|
||||
4
|
||||
} else {
|
||||
// 资源适中
|
||||
2
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 交付清单
|
||||
|
||||
### Phase 1 (2026-10-15)
|
||||
|
||||
**API 端点**:
|
||||
- ✅ `GET /api/v1/queue/status` - 队列状态
|
||||
- ✅ `PUT /api/v1/queue/task/{task_id}/priority` - 调整优先级
|
||||
- ✅ `DELETE /api/v1/queue/task/{task_id}` - 取消任务
|
||||
|
||||
**数据库**:
|
||||
- ✅ monitor_jobs 表扩展
|
||||
- ✅ 优先级索引
|
||||
|
||||
**Worker**:
|
||||
- ✅ 优先级队列处理
|
||||
- ✅ 基本重试(固定策略)
|
||||
|
||||
**前端集成**:
|
||||
- ✅ 轮询队列状态
|
||||
- ✅ 显示优先级和重试次数
|
||||
|
||||
### Phase 2 (2026-10-22)
|
||||
|
||||
**资源监控**:
|
||||
- ✅ CPU/RAM/GPU 监控
|
||||
- ✅ 3 秒采样间隔
|
||||
- ✅ 滑动窗口平均
|
||||
|
||||
**动态并发**:
|
||||
- ✅ 资源阈值调整
|
||||
- ✅ 30 秒调整间隔
|
||||
|
||||
### Phase 3 (2026-10-29)
|
||||
|
||||
**错误处理**:
|
||||
- ✅ 错误分类
|
||||
- ✅ 详细日志
|
||||
- ✅ 手动重试 API
|
||||
|
||||
**优化**:
|
||||
- ✅ 性能调优
|
||||
- ✅ 前端体验优化
|
||||
|
||||
---
|
||||
|
||||
## 测试计划
|
||||
|
||||
### 功能测试
|
||||
|
||||
```bash
|
||||
# 1. 提交多个任务
|
||||
curl -X POST "http://localhost:3002/api/v1/file/{uuid}/deep-scan" \
|
||||
-d '{"processors": ["face", "asr"], "priority": "high"}'
|
||||
|
||||
# 2. 查看队列状态
|
||||
curl "http://localhost:3002/api/v1/queue/status"
|
||||
|
||||
# 3. 调整优先级
|
||||
curl -X PUT "http://localhost:3002/api/v1/queue/task/{task_id}/priority" \
|
||||
-d '{"priority": "low"}'
|
||||
|
||||
# 4. 取消任务
|
||||
curl -X DELETE "http://localhost:3002/api/v1/queue/task/{task_id}"
|
||||
```
|
||||
|
||||
### 性能测试
|
||||
|
||||
```bash
|
||||
# 批量提交 50 个任务
|
||||
for i in {1..50}; do
|
||||
curl -X POST "http://localhost:3002/api/v1/file/{uuid_$i}/deep-scan"
|
||||
done
|
||||
|
||||
# 观察队列处理
|
||||
watch -n 1 'curl -s "http://localhost:3002/api/v1/queue/status" | jq ".active_count, .pending_count"'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 文档
|
||||
|
||||
- **需求文档**: `docs_v1.0/M4_workspace/2026-10-08_deep_scan_queue_feature_request.md`
|
||||
- **评估文档**: `docs_v1.0/M4_workspace/2026-10-08_deep_scan_queue_evaluation.md`
|
||||
- **澄清回复**: `docs_v1.0/M4_workspace/2026-10-08_deep_scan_queue_clarification.md`
|
||||
|
||||
---
|
||||
|
||||
**确认者**: Core Team
|
||||
**确认日期**: 2026-10-08
|
||||
**状态**: ✅ 所有澄清问题已回复
|
||||
**开始时间**: 立即开始 Phase 1
|
||||
Reference in New Issue
Block a user