diff --git a/internal/caches/storage_memory.go b/internal/caches/storage_memory.go index d56ee61..a102335 100644 --- a/internal/caches/storage_memory.go +++ b/internal/caches/storage_memory.go @@ -99,10 +99,19 @@ func (this *MemoryStorage) Init() error { // 启动定时Flush memory to disk任务 if this.parentStorage != nil { - // TODO 应该根据磁盘性能决定线程数 - // TODO 线程数应该可以在缓存策略和节点中设定 - var threads = runtime.NumCPU() - + var threads = 2 + var numCPU = runtime.NumCPU() + if fsutils.DiskIsExtremelyFast() { + if numCPU >= 8 { + threads = 8 + } else { + threads = 4 + } + } else if fsutils.DiskIsFast() { + if numCPU >= 4 { + threads = 4 + } + } for i := 0; i < threads; i++ { goman.New(func() { this.startFlush()