rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

GetOrRegister should use RLock #169

Closed dtjm closed 8 years ago

dtjm commented 8 years ago

We are using GetOrRegister in a place where it can be called frequently. Using a sync.RWMutex and using RLock/RUnlock instead of Lock/Unlock can increase performance here:

https://github.com/rcrowley/go-metrics/blob/master/registry.go#L80-L81

dtjm commented 8 years ago

Nevermind, it looks like we need to keep the lock for the entire duration of GetOrRegister or else you can have concurrent calls to it trying to register duplicate metrics.