优化单次清理LFU缓存数量逻辑

This commit is contained in:
GoEdgeLab
2023-09-15 14:46:31 +08:00
parent 82a8f101d4
commit bbb0c68fb0

View File

@@ -1072,7 +1072,15 @@ func (this *FileStorage) purgeLoop() {
// 磁盘空间不足时,清除老旧的缓存 // 磁盘空间不足时,清除老旧的缓存
if startLFU { if startLFU {
var maxCount = 2000
var maxLoops = 5 var maxLoops = 5
if fsutils.DiskIsFast() {
maxCount = 5000
} else if fsutils.DiskIsExtremelyFast() {
maxCount = 10000
}
for { for {
maxLoops-- maxLoops--
if maxLoops <= 0 { if maxLoops <= 0 {
@@ -1091,8 +1099,8 @@ func (this *FileStorage) purgeLoop() {
} }
// 限制单次清理的条数,防止占用太多系统资源 // 限制单次清理的条数,防止占用太多系统资源
if count > 2000 { if count > maxCount {
count = 2000 count = maxCount
} }
remotelogs.Println("CACHE", "LFU purge policy '"+this.policy.Name+"' id: "+types.String(this.policy.Id)+", count: "+types.String(count)) remotelogs.Println("CACHE", "LFU purge policy '"+this.policy.Name+"' id: "+types.String(this.policy.Id)+", count: "+types.String(count))