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
+5 -9
View File
@@ -13,11 +13,12 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
"kenaito-media-picker/internal/config"
uuid "github.com/satori/go.uuid"
)
@@ -30,15 +31,10 @@ type MoveJob struct {
// Mover 文件移动器。目前不需要记录任何状态,所以是个空壳结构体。
type Mover struct{}
// workerCount 并行搬文件的工人数:直接用满 CPU 核心数。
// 你的机器够强、平时又没别的活,那就让它全速跑,这就是空闲时的极限值。
// (如果搬文件的同时机器还在干别的活、被拖慢了,再手动把这个数调低即可。)
// workerCount 并行搬文件的工人数:默认 4 个(配置 organize.workers 可调,0 表示用满 CPU)。
// 搬文件时磁盘 IO 才是瓶颈,并发太大反而把 CPU/磁盘都拖垮,给个配置让用户自行权衡。
func workerCount() int {
n := runtime.NumCPU()
if n < 1 {
return 1
}
return n
return config.WorkerCount()
}
// MoveAll 把一批"搬文件任务"全局并行搬完——不管任务分散在几个目录,