Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dmitry-ee opened this issue Jun 15, 2022 · 0 comments
Open

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

dmitry-ee opened this issue Jun 15, 2022 · 0 comments

Comments

@dmitry-ee
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant