From 4f01a19e768ba404f81f3cda3906f98e240e69db Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 3 Sep 2021 15:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E6=A0=87=E6=95=B0=E6=8D=AE=E9=98=9F?= =?UTF-8?q?=E5=88=97=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=A4=A7=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=BF=87=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/metrics/task.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/metrics/task.go b/internal/metrics/task.go index 57e5202..9a415ae 100644 --- a/internal/metrics/task.go +++ b/internal/metrics/task.go @@ -19,6 +19,8 @@ import ( "time" ) +const MaxQueueSize = 10240 + // Task 单个指标任务 // 数据库存储: // data/ @@ -225,12 +227,15 @@ func (this *Task) Add(obj MetricInterface) { oldStat.Value += v oldStat.Hash = hash } else { - this.statsMap[hash] = &Stat{ - ServerId: obj.MetricServerId(), - Keys: keys, - Value: v, - Time: this.item.CurrentTime(), - Hash: hash, + // 防止过载 + if len(this.statsMap) < MaxQueueSize { + this.statsMap[hash] = &Stat{ + ServerId: obj.MetricServerId(), + Keys: keys, + Value: v, + Time: this.item.CurrentTime(), + Hash: hash, + } } } this.statsLocker.Unlock()