From 707ed03f1e237e346ef9b4e3d16de741f4c8d2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 25 Mar 2024 16:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=B3=BB=E7=BB=9F=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8A=A8=E6=80=81=E8=B0=83=E6=95=B4=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=88=B7=E5=85=A5=E7=A3=81=E7=9B=98=E7=BA=BF=E7=A8=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_memory.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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()