From 30ab0eec27648c8ecac45896fff7a5d65ffef58a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 15 Mar 2021 20:29:27 +0200 Subject: [PATCH] app/vmselect/promql: reduce overhead on scrape interval estimation It should be enough to use the first 20 datapoints instead of 100 datapoints for scrape interval estimation. --- app/vmselect/promql/rollup.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index c7f973a82..282b305aa 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -538,6 +538,7 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu // Do not drop trailing data points for queries, which return 2 or 1 point (aka instant queries). // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/845 canDropLastSample := rc.CanDropLastSample && len(rc.Timestamps) > 2 + f := rc.Func for _, tEnd := range rc.Timestamps { tStart := tEnd - window ni = seekFirstTimestampIdxAfter(timestamps[i:], tStart, ni) @@ -577,7 +578,7 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu rfa.realNextValue = nan } rfa.currTimestamp = tEnd - value := rc.Func(rfa) + value := f(rfa) rfa.idx++ dstValues = append(dstValues, value) } @@ -643,12 +644,12 @@ func getScrapeInterval(timestamps []int64) int64 { return int64(maxSilenceInterval) } - // Estimate scrape interval as 0.6 quantile for the first 100 intervals. + // Estimate scrape interval as 0.6 quantile for the first 20 intervals. h := histogram.GetFast() tsPrev := timestamps[0] timestamps = timestamps[1:] - if len(timestamps) > 100 { - timestamps = timestamps[:100] + if len(timestamps) > 20 { + timestamps = timestamps[:20] } for _, ts := range timestamps { h.Update(float64(ts - tsPrev))