mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
|
|
|
|
package bfs
|
|
|
|
import (
|
|
"time"
|
|
|
|
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
|
|
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
|
|
)
|
|
|
|
type FSOptions struct {
|
|
MaxOpenFiles int
|
|
BytesPerSync int64
|
|
SyncTimeout time.Duration
|
|
MaxSyncFiles int
|
|
}
|
|
|
|
func (this *FSOptions) EnsureDefaults() {
|
|
if this.MaxOpenFiles <= 0 {
|
|
// 根据内存计算最大打开文件数
|
|
var maxOpenFiles = memutils.SystemMemoryGB() * 128
|
|
if maxOpenFiles > (8 << 10) {
|
|
maxOpenFiles = 8 << 10
|
|
}
|
|
this.MaxOpenFiles = maxOpenFiles
|
|
}
|
|
if this.BytesPerSync <= 0 {
|
|
if fsutils.DiskIsFast() {
|
|
this.BytesPerSync = 1 << 20 // TODO 根据硬盘实际写入速度进行调整
|
|
} else {
|
|
this.BytesPerSync = 512 << 10
|
|
}
|
|
}
|
|
if this.SyncTimeout <= 0 {
|
|
this.SyncTimeout = 1 * time.Second
|
|
}
|
|
if this.MaxSyncFiles <= 0 {
|
|
this.MaxSyncFiles = 32
|
|
}
|
|
}
|
|
|
|
var DefaultFSOptions = &FSOptions{
|
|
MaxOpenFiles: 1 << 10,
|
|
BytesPerSync: 512 << 10,
|
|
SyncTimeout: 1 * time.Second,
|
|
MaxSyncFiles: 32,
|
|
}
|