rcrowley / go-metrics

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

Document how to create a threadsafe registry #165

Closed kevinburkeshyp closed 7 years ago

kevinburkeshyp commented 8 years ago

My first iteration of a metrics client had code like this:

// Increment a counter with the given name.
func Increment(name string) {
    mn := getWithNamespace(name)
    m := metrics.GetOrRegister(mn, metrics.NewMeter()).(metrics.Meter)
    m.Mark(1)
}

Which contained a massive resource leak - every anonymous NewMeter() call appends a new arbiter, so I had one arbiter for each function call! Instead document the right way to do this so people hopefully don't get as lost.

mihasya commented 7 years ago

Can't argue with more docs, though unfortunately this needs a rebase now :| sorry about my slowness.

kevinburkeshyp commented 7 years ago

Fixed conflict in #186 (I can't push to the branch in this PR anymore)