Skip to content

What's the best way to purge a metrics set? #34

@dmitry-ee

Description

@dmitry-ee

Hi,

I'm trying to implement some clean-up logic on metrics.Set

func generateMetricSet() *metrics.Set {
	ms := metrics.NewSet()
	total_metrics := 1000
	for total_metrics > 0 {
		ms.GetOrCreateCounter(RandStringBytesRmndr(50)).Set(uint64(rand.Int63()))
		total_metrics--
	}
	return ms
}

const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func RandStringBytesRmndr(n int) string {
	b := make([]byte, n)
	for i := range b {
		b[i] = letterBytes[rand.Int63() % int64(len(letterBytes))]
	}
	return string(b)
}

func BenchmarkMetricParser_Purge(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ms := generateMetricSet()
		for _,m := range ms.ListMetricNames() {
			ms.UnregisterMetric(m)
		}
	}
}
func BenchmarkMetricParser_Purge2(b *testing.B) {
	for i := 0; i < b.N; i++ {
		ms := generateMetricSet()
		_ = ms
		ms = nil
	}
}
BenchmarkMetricParser_Purge-4                458           5385638 ns/op          366105 B/op       4066 allocs/op
BenchmarkMetricParser_Purge2-4               618           3673018 ns/op          315736 B/op       4054 allocs/op

What's is a best approach to do the periodic cleanup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions