-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize SeriesGrouper & aggregators.merge
The previous implementation of SeriesGrouper required breaking a metric object apart into its constituents, converting tags and keys into unoptimized maps, only to have it put them back together into another metric object. This resulted in a significant performance overhead. This overhead was further compounded when the number of fields was large. This change adds a new AddMetric method to SeriesGrouper which preserves the metric object and removes the back-and-forth conversion. Additionlly the method used for calculating the metric's hash was switched to use maphash, which is optimized for this case. ---- Benchmarks Before: BenchmarkMergeOne-16 106012 11790 ns/op BenchmarkMergeTwo-16 48529 24819 ns/op BenchmarkGroupID-16 780018 1608 ns/op After: BenchmarkMergeOne-16 907093 1173 ns/op BenchmarkMergeTwo-16 508321 2168 ns/op BenchmarkGroupID-16 11217788 99.4 ns/op
- Loading branch information
Showing
4 changed files
with
148 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package metric | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
var m, _ = New( | ||
"mymetric", | ||
map[string]string{ | ||
"host": "host.example.com", | ||
"mykey": "myvalue", | ||
"another key": "another value", | ||
}, | ||
map[string]interface{}{ | ||
"f1": 1, | ||
"f2": 2, | ||
"f3": 3, | ||
"f4": 4, | ||
"f5": 5, | ||
"f6": 6, | ||
"f7": 7, | ||
"f8": 8, | ||
}, | ||
time.Now(), | ||
) | ||
|
||
var result uint64 | ||
|
||
func BenchmarkGroupID(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
result = groupID(m.Name(), m.TagList(), m.Time()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters