mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
优化缓存相关代码
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ var (
|
||||
|
||||
IsQuiting = false // 是否正在退出
|
||||
EnableDBStat = false // 是否开启本地数据库统计
|
||||
|
||||
DiskIsFast = false // 是否为高速硬盘
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user