From 5bdf62de5b06b49c6f918f20430bdd85959a4b30 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 17 Jan 2024 13:46:24 +0200 Subject: [PATCH] lib/storage: do not prefetch metric names for small number of metricIDs This eliminates prefetchedMetricIDsLock lock contention for queries, which return less than 500 time series. This is a follow-up for 9d886a2eb028ff5b8bb6b91f1d8214c165200bb6 --- lib/storage/storage.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 320beff76..32e2b39f1 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1141,8 +1141,9 @@ func (s *Storage) SearchMetricNames(qt *querytracer.Tracer, tfss []*TagFilters, func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, srcMetricIDs []uint64, deadline uint64) error { qt = qt.NewChild("prefetch metric names for %d metricIDs", len(srcMetricIDs)) defer qt.Done() - if len(srcMetricIDs) == 0 { - qt.Printf("nothing to prefetch") + + if len(srcMetricIDs) < 500 { + qt.Printf("skip pre-fetching metric names for low number of metric ids=%d", len(srcMetricIDs)) return nil } @@ -1160,7 +1161,7 @@ func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, srcMetricIDs []uin qt.Printf("%d out of %d metric names must be pre-fetched", len(metricIDs), len(srcMetricIDs)) if len(metricIDs) < 500 { // It is cheaper to skip pre-fetching and obtain metricNames inline. - qt.Printf("skip pre-fetching metric names for low number of metric ids=%d", len(metricIDs)) + qt.Printf("skip pre-fetching metric names for low number of missing metric ids=%d", len(metricIDs)) return nil } atomic.AddUint64(&s.slowMetricNameLoads, uint64(len(metricIDs)))