From 63b05c0b9f93818cbcd1ab289656c4e366c4b1b4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 8 Nov 2019 18:45:25 +0200 Subject: [PATCH] app/vmselect/promql: adjust memory limits calculations for incremental aggregate functions Incremental aggregate functions don't keep all the selected time series in memory - they keep only up to GOMAXPROCS time series for incremental aggregations. Take into account that the number of time series in RAM can be higher if they are split into many groups with `by (...)` or `without (...)` modifiers. This should reduce the number of `not enough memory for processing ... data points` false positive errors. --- app/vmselect/promql/eval.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/vmselect/promql/eval.go b/app/vmselect/promql/eval.go index c4094e511e..3f696b5f3c 100644 --- a/app/vmselect/promql/eval.go +++ b/app/vmselect/promql/eval.go @@ -595,7 +595,18 @@ func evalRollupFuncWithMetricExpr(ec *EvalConfig, name string, rf rollupFunc, me // Verify timeseries fit available memory after the rollup. // Take into account points from tssCached. pointsPerTimeseries := 1 + (ec.End-ec.Start)/ec.Step - rollupPoints := mulNoOverflow(pointsPerTimeseries, int64(rssLen*len(rcs))) + timeseriesLen := rssLen + if iafc != nil { + // Incremental aggregates require hold only GOMAXPROCS timeseries in memory. + timeseriesLen = runtime.GOMAXPROCS(-1) + if iafc.ae.Modifier.Op != "" { + // Increase the number of timeseries for non-empty group list: `aggr() by (something)`, + // since each group can have own set of time series in memory. + // Estimate the number of such groups is lower than 100 :) + timeseriesLen *= 100 + } + } + rollupPoints := mulNoOverflow(pointsPerTimeseries, int64(timeseriesLen*len(rcs))) rollupMemorySize := mulNoOverflow(rollupPoints, 16) rml := getRollupMemoryLimiter() if !rml.Get(uint64(rollupMemorySize)) {