From 6a0cf2cd2984a5bff3deac91779c9c261b8002b9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 25 Jun 2024 03:01:36 +0200 Subject: [PATCH] app/vmselect/netstorage: add a comment explaining why all the samples in block are taken into account when checking the -search.maxSamplesPerQuery limit Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5851 This is a follow-up for b07a02c5161950ab735f9d0762b32252a8debc27 --- app/vmselect/netstorage/netstorage.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 8282aeeb9..f9760f69f 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -1192,6 +1192,11 @@ func ProcessSearchQuery(qt *querytracer.Tracer, sq *storage.SearchQuery, deadlin return nil, fmt.Errorf("timeout exceeded while fetching data block #%d from storage: %s", blocksRead, deadline.String()) } br := sr.MetricBlockRef.BlockRef + + // Take into account all the samples in the block when checking for *maxSamplesPerQuery limit, + // since CPU time is spent on unpacking all the samples in the block, even if only a few samples + // are left then because of the given time range. + // This allows effectively limiting CPU resources used per query. samples += br.RowsCount() if *maxSamplesPerQuery > 0 && samples > *maxSamplesPerQuery { putTmpBlocksFile(tbf)