perf: 并发worker数可配置(默认4)与MIME检测并行化

This commit is contained in:
2025-05-28 21:16:15 +08:00
parent cf8d991974
commit 0aa9d44025
5 changed files with 69 additions and 23 deletions
+4 -8
View File
@@ -14,12 +14,12 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
"kenaito-media-picker/internal/classify"
"kenaito-media-picker/internal/config"
"kenaito-media-picker/internal/digest"
"kenaito-media-picker/internal/mover"
"kenaito-media-picker/internal/probe"
@@ -93,14 +93,10 @@ func (o *Organizer) report(phase string, done, total int) {
// ============================ 并行小工具 ============================
// workerCount 并行探测的工人数:直接用满 CPU 核心数(空闲时的极限值)。
// 多核机器并行探测能明显提速;如果机器同时还在跑别的重活,再手动调低即可。
// workerCount 并行探测的工人数:默认 4 个(配置 organize.workers 可调,0 表示用满 CPU)。
// 多核机器并行探测能明显提速;但并发太大会吃满 CPU,给个配置让用户自行权衡。
func workerCount() int {
n := runtime.NumCPU()
if n < 1 {
return 1
}
return n
return config.WorkerCount()
}
// runParallel 用固定数量的工人并行处理一批东西,结果按原来的顺序放回。