From 993d798bb939bb43314dd46d410747f2df0051a3 Mon Sep 17 00:00:00 2001 From: Angelo Marletta Date: Sat, 1 Jun 2024 01:07:51 -0700 Subject: [PATCH] Optimistic allocation --- statsd/aggregator.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/statsd/aggregator.go b/statsd/aggregator.go index e8178f27..03629d29 100644 --- a/statsd/aggregator.go +++ b/statsd/aggregator.go @@ -234,6 +234,8 @@ func (a *aggregator) count(name string, value int64, tags []string, cardinality } a.countsM.RUnlock() + metric := newCountMetric(name, value, tags, resolvedCardinality) + a.countsM.Lock() // Check if another goroutines hasn't created the value betwen the RUnlock and 'Lock' if count, found := a.counts[context]; found { @@ -242,7 +244,7 @@ func (a *aggregator) count(name string, value int64, tags []string, cardinality return nil } - a.counts[context] = newCountMetric(name, value, tags, resolvedCardinality) + a.counts[context] = metric a.countsM.Unlock() return nil } @@ -283,6 +285,8 @@ func (a *aggregator) set(name string, value string, tags []string, cardinality C } a.setsM.RUnlock() + metric := newSetMetric(name, value, tags, resolvedCardinality) + a.setsM.Lock() // Check if another goroutines hasn't created the value betwen the 'RUnlock' and 'Lock' if set, found := a.sets[context]; found { @@ -290,7 +294,7 @@ func (a *aggregator) set(name string, value string, tags []string, cardinality C a.setsM.Unlock() return nil } - a.sets[context] = newSetMetric(name, value, tags, resolvedCardinality) + a.sets[context] = metric a.setsM.Unlock() return nil }