Avoid allocation when counting tag keys

A new sorted slice was called by the monitor func every 10s.  The
tag keys don't need to be sorted so this avoid the allocation of the
slice and one during sorting.
pull/7631/head
Jason Wilder 2016-11-10 18:22:24 -07:00
parent 0ee58c208a
commit bf17074f58
2 changed files with 13 additions and 2 deletions

View File

@ -1893,6 +1893,17 @@ func MarshalTags(tags map[string]string) []byte {
return b
}
// WalkTagKeys calls fn for each tag key associated with m. The order of the
// keys is undefined.
func (m *Measurement) WalkTagKeys(fn func(k string)) {
m.mu.RLock()
defer m.mu.RUnlock()
for k := range m.seriesByTagKeyValue {
fn(k)
}
}
// TagKeys returns a list of the measurement's tag names.
func (m *Measurement) TagKeys() []string {
m.mu.RLock()

View File

@ -853,7 +853,7 @@ func (s *Shard) monitor() {
}
for _, m := range s.index.Measurements() {
for _, k := range m.TagKeys() {
m.WalkTagKeys(func(k string) {
n := m.Cardinality(k)
perc := int(float64(n) / float64(s.options.Config.MaxValuesPerTag) * 100)
if perc > 100 {
@ -865,7 +865,7 @@ func (s *Shard) monitor() {
s.logger.Printf("WARN: %d%% of max-values-per-tag limit exceeded: (%d/%d), db=%s shard=%d measurement=%s tag=%s",
perc, n, s.options.Config.MaxValuesPerTag, s.database, s.id, m.Name, k)
}
}
})
}
}
}