From bd3bcdc43c9086760f0e549f154860434d50ad5e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 21 Feb 2021 21:32:52 +0200 Subject: [PATCH] lib/storage: do not re-calculate stats for heavy tag filters This should reduce the number of slow queries when stats for heavy tag filters was recalculated. --- lib/storage/index_db.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 792a8e116..61a3419c8 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -2822,9 +2822,12 @@ func (is *indexSearch) getMetricIDsForDateAndFilters(date uint64, tfs *TagFilter tf := &tfs.tfs[i] loopsCount, lastQueryTimestamp := is.getLoopsCountAndTimestampForDateFilter(date, tf) origLoopsCount := loopsCount - if currentTime > lastQueryTimestamp+60*60 { - // Reset loopsCount to 0 every hour for collecting updated stats for the tf. - loopsCount = 0 + if currentTime > lastQueryTimestamp+3*3600 { + // Update stats once per 3 hours only for relatively fast tag filters. + // There is no need in spending CPU resources on updating stats for slow tag filters. + if loopsCount <= 10e6 { + loopsCount = 0 + } } if loopsCount == 0 { // Prevent from possible thundering herd issue when heavy tf is executed from multiple concurrent queries