mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 03:50:27 +08:00
优化缓存自动清理逻辑
This commit is contained in:
@@ -1001,6 +1001,11 @@ func (this *FileStorage) initList() error {
|
||||
// 清理任务
|
||||
// TODO purge每个分区
|
||||
func (this *FileStorage) purgeLoop() {
|
||||
// load
|
||||
systemLoad, _ := load.Avg()
|
||||
|
||||
// TODO 计算平均最近每日新增用量
|
||||
|
||||
// 计算是否应该开启LFU清理
|
||||
var capacityBytes = this.diskCapacityBytes()
|
||||
var startLFU = false
|
||||
@@ -1009,6 +1014,7 @@ func (this *FileStorage) purgeLoop() {
|
||||
if lfuFreePercent <= 0 {
|
||||
lfuFreePercent = 5
|
||||
|
||||
if systemLoad == nil || systemLoad.Load5 > 10 {
|
||||
// 2TB级别以上
|
||||
if capacityBytes>>30 > 2000 {
|
||||
lfuFreePercent = 100 /** GB **/ / float32(capacityBytes>>30) * 100 /** % **/
|
||||
@@ -1017,6 +1023,7 @@ func (this *FileStorage) purgeLoop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var hasFullDisk = this.hasFullDisk()
|
||||
if hasFullDisk {
|
||||
@@ -1037,7 +1044,6 @@ func (this *FileStorage) purgeLoop() {
|
||||
var times = 1
|
||||
|
||||
// 空闲时间多清理
|
||||
systemLoad, _ := load.Avg()
|
||||
if systemLoad != nil {
|
||||
if systemLoad.Load5 < 3 {
|
||||
times = 5
|
||||
@@ -1102,13 +1108,13 @@ func (this *FileStorage) purgeLoop() {
|
||||
|
||||
// 磁盘空间不足时,清除老旧的缓存
|
||||
if startLFU {
|
||||
var maxCount = 2000
|
||||
var maxCount = 1000
|
||||
var maxLoops = 5
|
||||
|
||||
if fsutils.DiskIsExtremelyFast() {
|
||||
maxCount = 10000
|
||||
maxCount = 4000
|
||||
} else if fsutils.DiskIsFast() {
|
||||
maxCount = 5000
|
||||
maxCount = 2000
|
||||
}
|
||||
|
||||
var total, _ = this.list.Count()
|
||||
|
||||
Reference in New Issue
Block a user