github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/bfs/fs_options.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package bfs 4 5 import ( 6 fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs" 7 memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem" 8 "time" 9 ) 10 11 type FSOptions struct { 12 MaxOpenFiles int 13 BytesPerSync int64 14 SyncTimeout time.Duration 15 MaxSyncFiles int 16 } 17 18 func (this *FSOptions) EnsureDefaults() { 19 if this.MaxOpenFiles <= 0 { 20 // 根据内存计算最大打开文件数 21 var maxOpenFiles = memutils.SystemMemoryGB() * 128 22 if maxOpenFiles > (8 << 10) { 23 maxOpenFiles = 8 << 10 24 } 25 this.MaxOpenFiles = maxOpenFiles 26 } 27 if this.BytesPerSync <= 0 { 28 if fsutils.DiskIsFast() { 29 this.BytesPerSync = 1 << 20 // TODO 根据硬盘实际写入速度进行调整 30 } else { 31 this.BytesPerSync = 512 << 10 32 } 33 } 34 if this.SyncTimeout <= 0 { 35 this.SyncTimeout = 1 * time.Second 36 } 37 if this.MaxSyncFiles <= 0 { 38 this.MaxSyncFiles = 32 39 } 40 } 41 42 var DefaultFSOptions = &FSOptions{ 43 MaxOpenFiles: 1 << 10, 44 BytesPerSync: 512 << 10, 45 SyncTimeout: 1 * time.Second, 46 MaxSyncFiles: 32, 47 }