From 2b76fd446340245dbb6fc6df6cd3a4d376a7208a Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 14 Apr 2022 10:25:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 14 ++++++++++++-- internal/const/vars.go | 2 ++ internal/nodes/node.go | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 9312370..6f73626 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -27,6 +27,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "sort" "strconv" "strings" @@ -62,7 +63,16 @@ const ( var sharedWritingFileKeyMap = map[string]zero.Zero{} // key => bool var sharedWritingFileKeyLocker = sync.Mutex{} -var maxOpenFiles = 2 +var maxOpenFiles = 3 + +func init() { + if teaconst.DiskIsFast { + maxOpenFiles = runtime.NumCPU() + } + if maxOpenFiles < 3 { + maxOpenFiles = 3 + } +} // FileStorage 文件缓存 // 文件结构: @@ -425,7 +435,7 @@ func (this *FileStorage) openWriter(key string, expiredAt int64, status int, siz return nil, ErrFileIsWriting } - if len(sharedWritingFileKeyMap) > maxOpenFiles { + if !isFlushing && len(sharedWritingFileKeyMap) >= maxOpenFiles { sharedWritingFileKeyLocker.Unlock() return nil, ErrTooManyOpenFiles } diff --git a/internal/const/vars.go b/internal/const/vars.go index 8f7a3d0..fdfc8e7 100644 --- a/internal/const/vars.go +++ b/internal/const/vars.go @@ -17,4 +17,6 @@ var ( IsQuiting = false // 是否正在退出 EnableDBStat = false // 是否开启本地数据库统计 + + DiskIsFast = false // 是否为高速硬盘 ) diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 1a815d9..4750f88 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -111,6 +111,9 @@ func (this *Node) Start() { return } + // 检查硬盘类型 + this.checkDisk() + // 读取API配置 err = this.syncConfig(0) if err != nil { @@ -911,3 +914,21 @@ func (this *Node) onReload(config *nodeconfigs.NodeConfig) { teaconst.GlobalProductName = config.ProductConfig.Name } } + +func (this *Node) checkDisk() { + if runtime.GOOS == "linux" { + for _, path := range []string{ + "/sys/block/vda/queue/rotational", + "/sys/block/sda/queue/rotational", + } { + data, err := ioutil.ReadFile(path) + if err != nil { + continue + } + if string(data) == "0" { + teaconst.DiskIsFast = true + } + break + } + } +}