From 41fe707bec5555f5e441d7a291d6726b9ce46834 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 17 Mar 2021 00:46:22 +0200 Subject: [PATCH] lib/storage: limit loops count in order to reduce max CPU usage during filter search --- lib/storage/index_db.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 5866c25d5..c7c5e3c71 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -2979,6 +2979,9 @@ func (is *indexSearch) getMetricIDsForDateAndFilters(date uint64, tfs *TagFilter break } maxLoopsCount := getFirstPositiveFilterLoopsCount(tfws[i+1:]) + if maxLoopsCount == int64Max { + maxLoopsCount = int64(metricIDsLen) * loopsCountPerMetricNameMatch + } m, filterLoopsCount, err := is.getMetricIDsForDateTagFilter(tf, date, tfs.commonPrefix, intMax, maxLoopsCount) if err != nil { if errors.Is(err, errTooManyLoops) {