Skip to content

Commit 5d6607c

Browse files
authored
Merge pull request #308 from opsengine/optimistic-allocation
Optimistic allocation for Count and Set metrics
2 parents 00fb40e + 993d798 commit 5d6607c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

statsd/aggregator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ func (a *aggregator) count(name string, value int64, tags []string, cardinality
234234
}
235235
a.countsM.RUnlock()
236236

237+
metric := newCountMetric(name, value, tags, resolvedCardinality)
238+
237239
a.countsM.Lock()
238240
// Check if another goroutines hasn't created the value betwen the RUnlock and 'Lock'
239241
if count, found := a.counts[context]; found {
@@ -242,7 +244,7 @@ func (a *aggregator) count(name string, value int64, tags []string, cardinality
242244
return nil
243245
}
244246

245-
a.counts[context] = newCountMetric(name, value, tags, resolvedCardinality)
247+
a.counts[context] = metric
246248
a.countsM.Unlock()
247249
return nil
248250
}
@@ -283,14 +285,16 @@ func (a *aggregator) set(name string, value string, tags []string, cardinality C
283285
}
284286
a.setsM.RUnlock()
285287

288+
metric := newSetMetric(name, value, tags, resolvedCardinality)
289+
286290
a.setsM.Lock()
287291
// Check if another goroutines hasn't created the value betwen the 'RUnlock' and 'Lock'
288292
if set, found := a.sets[context]; found {
289293
set.sample(value)
290294
a.setsM.Unlock()
291295
return nil
292296
}
293-
a.sets[context] = newSetMetric(name, value, tags, resolvedCardinality)
297+
a.sets[context] = metric
294298
a.setsM.Unlock()
295299
return nil
296300
}

0 commit comments

Comments
 (0)