Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic metric allocation #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions statsd/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func (a *aggregator) count(name string, value int64, tags []string) error {
}
a.countsM.RUnlock()

metric := newCountMetric(name, value, tags)

a.countsM.Lock()
// Check if another goroutines hasn't created the value betwen the RUnlock and 'Lock'
if count, found := a.counts[context]; found {
Expand All @@ -227,7 +229,7 @@ func (a *aggregator) count(name string, value int64, tags []string) error {
return nil
}

a.counts[context] = newCountMetric(name, value, tags)
a.counts[context] = metric
a.countsM.Unlock()
return nil
}
Expand All @@ -242,7 +244,7 @@ func (a *aggregator) gauge(name string, value float64, tags []string) error {
}
a.gaugesM.RUnlock()

gauge := newGaugeMetric(name, value, tags)
metric := newGaugeMetric(name, value, tags)

a.gaugesM.Lock()
// Check if another goroutines hasn't created the value betwen the 'RUnlock' and 'Lock'
Expand All @@ -251,7 +253,7 @@ func (a *aggregator) gauge(name string, value float64, tags []string) error {
a.gaugesM.Unlock()
return nil
}
a.gauges[context] = gauge
a.gauges[context] = metric
a.gaugesM.Unlock()
return nil
}
Expand All @@ -266,14 +268,16 @@ func (a *aggregator) set(name string, value string, tags []string) error {
}
a.setsM.RUnlock()

metric := newSetMetric(name, value, tags)

a.setsM.Lock()
// Check if another goroutines hasn't created the value betwen the 'RUnlock' and 'Lock'
if set, found := a.sets[context]; found {
set.sample(value)
a.setsM.Unlock()
return nil
}
a.sets[context] = newSetMetric(name, value, tags)
a.sets[context] = metric
a.setsM.Unlock()
return nil
}
Expand Down