MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / purgeLoop

Method purgeLoop

internal/caches/storage_file.go:1080–1242  ·  view source on GitHub ↗

清理任务 TODO purge每个分区

()

Source from the content-addressed store, hash-verified

1078// 清理任务
1079// TODO purge每个分区
1080func (this *FileStorage) purgeLoop() {
1081 // load
1082 systemLoad, _ := load.Avg()
1083
1084 // TODO 计算平均最近每日新增用量
1085
1086 // 计算是否应该开启LFU清理
1087 var capacityBytes = this.diskCapacityBytes()
1088 var startLFU = false
1089 var requireFullLFU = false // 是否需要完整执行LFU
1090 var lfuFreePercent = this.policy.PersistenceLFUFreePercent
1091 if lfuFreePercent <= 0 {
1092 lfuFreePercent = 5
1093
1094 if systemLoad == nil || systemLoad.Load5 > 10 {
1095 // 2TB级别以上
1096 if capacityBytes>>30 > 2000 {
1097 lfuFreePercent = 100 /** GB **/ / float32(capacityBytes>>30) * 100 /** % **/
1098 if lfuFreePercent > 3 {
1099 lfuFreePercent = 3
1100 }
1101 }
1102 }
1103 }
1104
1105 var hasFullDisk = this.hasFullDisk()
1106 if hasFullDisk {
1107 startLFU = true
1108 } else {
1109 var usedPercent = float32(this.TotalDiskSize()*100) / float32(capacityBytes)
1110 if capacityBytes > 0 {
1111 if lfuFreePercent < 100 {
1112 if usedPercent >= 100-lfuFreePercent {
1113 startLFU = true
1114 }
1115 }
1116 }
1117 }
1118
1119 // 清理过期
1120 {
1121 var times = 1
1122
1123 // 空闲时间多清理
1124 if systemLoad != nil {
1125 if systemLoad.Load5 < 3 {
1126 times = 5
1127 } else if systemLoad.Load5 < 5 {
1128 times = 3
1129 } else if systemLoad.Load5 < 10 {
1130 times = 2
1131 }
1132 }
1133
1134 // 高速硬盘多清理
1135 if fsutils.DiskIsExtremelyFast() {
1136 times *= 8
1137 } else if fsutils.DiskIsFast() {

Callers 2

initPurgeTickerMethod · 0.95
TestFileStorage_InitFunction · 0.45

Calls 13

diskCapacityBytesMethod · 0.95
hasFullDiskMethod · 0.95
TotalDiskSizeMethod · 0.95
hashPathMethod · 0.95
removeCacheFileMethod · 0.95
ErrorFunction · 0.92
WarnFunction · 0.92
PrintlnFunction · 0.92
PurgeMethod · 0.65
CountMethod · 0.65
PurgeLFUMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestFileStorage_InitFunction · 0.36