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

Optimize label sorting #219

Merged
merged 2 commits into from
May 17, 2019
Merged

Conversation

claytono
Copy link
Contributor

Previously we were sorting labels in every container to build a map key, but also when generating the hash key by calling the LabelsToSignature method. This moves the sorting to be done early in the event processing then passes the sorted label array around.

Before:

$ /usr/local/bin/go test -benchmem -run=^$ github.com/prometheus/statsd_exporter -bench '^(BenchmarkHashNameAndLabels)$' -benchtime 5s
goos: darwin
goarch: amd64
pkg: github.com/prometheus/statsd_exporter
BenchmarkHashNameAndLabels/no_labels-8          300000000               26.7 ns/op             0 B/op          0 allocs/op
BenchmarkHashNameAndLabels/one_label-8          50000000               163 ns/op              48 B/op          2 allocs/op
BenchmarkHashNameAndLabels/many_labels-8        10000000               889 ns/op             192 B/op          2 allocs/op
PASS
ok      github.com/prometheus/statsd_exporter   28.928s

After:

$ /usr/local/bin/go test -benchmem -run=^$ github.com/prometheus/statsd_exporter -bench '^(BenchmarkHashNameAndLabels)$' -benchtime 5s
goos: darwin
goarch: amd64
pkg: github.com/prometheus/statsd_exporter
BenchmarkHashNameAndLabels/no_labels-8          300000000               21.5 ns/op             0 B/op          0 allocs/op
BenchmarkHashNameAndLabels/one_label-8          100000000               59.8 ns/op             0 B/op          0 allocs/op
BenchmarkHashNameAndLabels/many_labels-8        20000000               507 ns/op               0 B/op          0 allocs/op
PASS
ok      github.com/prometheus/statsd_exporter   25.530s

claytono added 2 commits May 16, 2019 17:17
Signed-off-by: Clayton O'Neill <claytono@github.com>
Previously we were sorting labels in every container to build a map key,
but also when generating the hash key by calling the `LabelsToSignature`
method.  This moves the sorting to be done early in the event processing
then passes the sorted label array around.

Signed-off-by: Clayton O'Neill <claytono@github.com>
@matthiasr matthiasr merged commit c9004f8 into prometheus:master May 17, 2019
@matthiasr
Copy link
Contributor

Cheers!

matthiasr pushed a commit that referenced this pull request May 17, 2019
Signed-off-by: Matthias Rampke <mr@soundcloud.com>
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

Successfully merging this pull request may close these issues.

2 participants