From c76a904bb0d01bf1bba44fcd01f7433a5cbaf1a9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 7 Mar 2021 21:12:28 +0200 Subject: [PATCH] lib/storage: tune loopsCount estimations in getMetricIDsForTagFilterSlow The adjusted estmations give up to 2x lower median response times on 200qps /api/v1/query_range workload --- lib/storage/index_db.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index e56bcb550..35a06c9cf 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -154,8 +154,8 @@ func openIndexDB(path string, metricIDCache, metricNameCache, tsidCache *working metricIDCache: metricIDCache, metricNameCache: metricNameCache, tsidCache: tsidCache, - uselessTagFiltersCache: workingsetcache.New(mem/128, 3*time.Hour), - loopsPerDateTagFilterCache: workingsetcache.New(mem/128, 3*time.Hour), + uselessTagFiltersCache: workingsetcache.New(mem/128, time.Hour), + loopsPerDateTagFilterCache: workingsetcache.New(mem/128, time.Hour), minTimestampForCompositeIndex: minTimestampForCompositeIndex, } @@ -2483,7 +2483,8 @@ func (is *indexSearch) getMetricIDsForTagFilterSlow(tf *tagFilter, filter *uint6 } // Slow path: need tf.matchSuffix call. ok, err := tf.matchSuffix(suffix) - loopsCount += tf.matchCost + // Assume that tf.matchSuffix call needs 10x more time than a single metric scan iteration. + loopsCount += 10*tf.matchCost if err != nil { return loopsCount, fmt.Errorf("error when matching %s against suffix %q: %w", tf, suffix, err) } @@ -2504,8 +2505,8 @@ func (is *indexSearch) getMetricIDsForTagFilterSlow(tf *tagFilter, filter *uint6 } kb.B[len(kb.B)-1]++ ts.Seek(kb.B) - // Assume that a seek cost is equivalent to 100 ordinary loops. - loopsCount += 100 + // Assume that a seek cost is equivalent to 1000 ordinary loops. + loopsCount += 1000 continue } prevMatch = true