指标数据队列增加最大数量限制,防止过载

This commit is contained in:
刘祥超
2021-09-03 15:38:56 +08:00
parent 699cea4382
commit dd41d88647

View File

@@ -19,6 +19,8 @@ import (
"time" "time"
) )
const MaxQueueSize = 10240
// Task 单个指标任务 // Task 单个指标任务
// 数据库存储: // 数据库存储:
// data/ // data/
@@ -225,12 +227,15 @@ func (this *Task) Add(obj MetricInterface) {
oldStat.Value += v oldStat.Value += v
oldStat.Hash = hash oldStat.Hash = hash
} else { } else {
this.statsMap[hash] = &Stat{ // 防止过载
ServerId: obj.MetricServerId(), if len(this.statsMap) < MaxQueueSize {
Keys: keys, this.statsMap[hash] = &Stat{
Value: v, ServerId: obj.MetricServerId(),
Time: this.item.CurrentTime(), Keys: keys,
Hash: hash, Value: v,
Time: this.item.CurrentTime(),
Hash: hash,
}
} }
} }
this.statsLocker.Unlock() this.statsLocker.Unlock()