Skip to content

Commit

Permalink
Merge pull request #288 from iksaif/corentin.chary/fix-contention
Browse files Browse the repository at this point in the history
aggregator: avoid extra-locking in bufferedMetric.sample()
  • Loading branch information
remeh authored Oct 24, 2023
2 parents f614269 + 36eb411 commit e612112
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions statsd/buffered_metric_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (bc *bufferedMetricContexts) sample(name string, value float64, tags []stri
bc.mutex.RUnlock()

// Create it if it wasn't found
bc.mutex.Lock()
if v == nil {
bc.mutex.Lock()
// It might have been created by another goroutine since last call
v, _ = bc.values[context]
if v == nil {
Expand All @@ -76,8 +76,8 @@ func (bc *bufferedMetricContexts) sample(name string, value float64, tags []stri
bc.mutex.Unlock()
return nil
}
bc.mutex.Unlock()
}
bc.mutex.Unlock()

// Now we can keep the sample or skip it
if keepingSample {
Expand Down

0 comments on commit e612112

Please sign in to comment.