mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-05 01:01:09 +01:00
lib/storage: optimize BenchmarkIndexDBGetTSIDs()
- Sort MetricName tags only once before the benchmark loop. - Obtain indexSearch per each benchmark loop in order to give a chance for background merge for the recently created parts
This commit is contained in:
parent
443661a5da
commit
3dacdcb707
@ -136,14 +136,15 @@ func BenchmarkHeadPostingForMatchers(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
benchSearch := func(b *testing.B, tfs *TagFilters, expectedMetricIDs int) {
|
benchSearch := func(b *testing.B, tfs *TagFilters, expectedMetricIDs int) {
|
||||||
is := db.getIndexSearch(noDeadline)
|
|
||||||
tfss := []*TagFilters{tfs}
|
tfss := []*TagFilters{tfs}
|
||||||
tr := TimeRange{
|
tr := TimeRange{
|
||||||
MinTimestamp: 0,
|
MinTimestamp: 0,
|
||||||
MaxTimestamp: timestampFromTime(time.Now()),
|
MaxTimestamp: timestampFromTime(time.Now()),
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
is := db.getIndexSearch(noDeadline)
|
||||||
metricIDs, err := is.searchMetricIDs(nil, tfss, tr, 2e9)
|
metricIDs, err := is.searchMetricIDs(nil, tfss, tr, 2e9)
|
||||||
|
db.putIndexSearch(is)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("unexpected error in searchMetricIDs: %s", err)
|
b.Fatalf("unexpected error in searchMetricIDs: %s", err)
|
||||||
}
|
}
|
||||||
@ -151,7 +152,6 @@ func BenchmarkHeadPostingForMatchers(b *testing.B) {
|
|||||||
b.Fatalf("unexpected metricIDs found; got %d; want %d", len(metricIDs), expectedMetricIDs)
|
b.Fatalf("unexpected metricIDs found; got %d; want %d", len(metricIDs), expectedMetricIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.putIndexSearch(is)
|
|
||||||
}
|
}
|
||||||
addTagFilter := func(tfs *TagFilters, key, value string, isNegative, isRegexp bool) {
|
addTagFilter := func(tfs *TagFilters, key, value string, isNegative, isRegexp bool) {
|
||||||
if err := tfs.Add([]byte(key), []byte(value), isNegative, isRegexp); err != nil {
|
if err := tfs.Add([]byte(key), []byte(value), isNegative, isRegexp); err != nil {
|
||||||
@ -281,15 +281,16 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) {
|
|||||||
value := fmt.Sprintf("value_%d", i)
|
value := fmt.Sprintf("value_%d", i)
|
||||||
mn.AddTag(key, value)
|
mn.AddTag(key, value)
|
||||||
}
|
}
|
||||||
|
mn.sortTags()
|
||||||
|
|
||||||
var genTSID generationTSID
|
var genTSID generationTSID
|
||||||
var metricNameRaw []byte
|
var metricNameRaw []byte
|
||||||
date := uint64(0)
|
date := uint64(12345)
|
||||||
|
|
||||||
is := db.getIndexSearch(noDeadline)
|
is := db.getIndexSearch(noDeadline)
|
||||||
defer db.putIndexSearch(is)
|
defer db.putIndexSearch(is)
|
||||||
|
|
||||||
for i := 0; i < recordsCount; i++ {
|
for i := 0; i < recordsCount; i++ {
|
||||||
mn.sortTags()
|
|
||||||
metricNameRaw = mn.marshalRaw(metricNameRaw[:0])
|
metricNameRaw = mn.marshalRaw(metricNameRaw[:0])
|
||||||
generateTSID(&genTSID.TSID, &mn)
|
generateTSID(&genTSID.TSID, &mn)
|
||||||
genTSID.generation = db.generation
|
genTSID.generation = db.generation
|
||||||
@ -303,18 +304,19 @@ func BenchmarkIndexDBGetTSIDs(b *testing.B) {
|
|||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
var genTSIDLocal generationTSID
|
var genTSIDLocal generationTSID
|
||||||
var metricNameLocal []byte
|
var metricNameLocal []byte
|
||||||
mnLocal := mn
|
var mnLocal MetricName
|
||||||
is := db.getIndexSearch(noDeadline)
|
mnLocal.CopyFrom(&mn)
|
||||||
|
mnLocal.sortTags()
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
|
is := db.getIndexSearch(noDeadline)
|
||||||
for i := 0; i < recordsPerLoop; i++ {
|
for i := 0; i < recordsPerLoop; i++ {
|
||||||
mnLocal.sortTags()
|
|
||||||
metricNameLocal = mnLocal.Marshal(metricNameLocal[:0])
|
metricNameLocal = mnLocal.Marshal(metricNameLocal[:0])
|
||||||
if !is.getTSIDByMetricName(&genTSIDLocal, metricNameLocal, date) {
|
if !is.getTSIDByMetricName(&genTSIDLocal, metricNameLocal, date) {
|
||||||
panic(fmt.Errorf("cannot obtain tsid for row %d", i))
|
panic(fmt.Errorf("cannot obtain tsid for row %d", i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
db.putIndexSearch(is)
|
||||||
}
|
}
|
||||||
db.putIndexSearch(is)
|
|
||||||
})
|
})
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user