根据系统环境动态调整内容刷入磁盘线程数

This commit is contained in:
刘祥超
2024-03-25 16:36:29 +08:00
parent 07080b13ee
commit 707ed03f1e

View File

@@ -99,10 +99,19 @@ func (this *MemoryStorage) Init() error {
// 启动定时Flush memory to disk任务 // 启动定时Flush memory to disk任务
if this.parentStorage != nil { if this.parentStorage != nil {
// TODO 应该根据磁盘性能决定线程数 var threads = 2
// TODO 线程数应该可以在缓存策略和节点中设定 var numCPU = runtime.NumCPU()
var threads = 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++ { for i := 0; i < threads; i++ {
goman.New(func() { goman.New(func() {
this.startFlush() this.startFlush()