-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[PERF] PromQL: Split rangeEval for binary operations #16698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I've raised #16797 extending the perf gains due to concrete types, without the code duplication of splitting |
A quick scan suggests this one is faster. Did I miss something? |
Can you run the full benchmark please? Since this PR only updates the binops, other operations should be unaffected. I will run mine with |
I ran the full set of benchmarks; there were some regressions like Happy to accept #16797, maybe with some tweaks, but I still want to break out |
Currently, the promql functions take the interface slice []parser.Value as an argument, which is being implemented by the conrete types Vector, Matrix etc. This PR replaces the interface with the concrete types, resulting in improved performance. The inspiration for this PR came from #16698 which does this for binops. I extended the idea to all promql functions Signed-off-by: darshanime <deathbullet@gmail.com> * pass single Matrix Signed-off-by: darshanime <deathbullet@gmail.com> --------- Signed-off-by: darshanime <deathbullet@gmail.com>
) Currently, the promql functions take the interface slice []parser.Value as an argument, which is being implemented by the conrete types Vector, Matrix etc. This PR replaces the interface with the concrete types, resulting in improved performance. The inspiration for this PR came from prometheus#16698 which does this for binops. I extended the idea to all promql functions Signed-off-by: darshanime <deathbullet@gmail.com> * pass single Matrix Signed-off-by: darshanime <deathbullet@gmail.com> --------- Signed-off-by: darshanime <deathbullet@gmail.com> Signed-off-by: Andrew Hall <andrew.hall@grafana.com>
To make subsequent changes easier. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This means we can simplify the non-binop version that doesn't need the `prepSeries` function. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This is more efficient as it avoids converting Vector arguments to parser.Value. Allow matching parameter to be nil to signal we don't need signatures. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
7bc5038
to
375727e
Compare
[Update: the performance improvement got done #16797; this is now a refactor]
Binary operations generally involve matching left-hand series against right-hand series, for which we had the
prepSeries
function pre-computing signatures.The genesis of this refactor is that I didn't understand what was going on in #9577, so I tried to simplify the code leading up to it.
Along the way, some other functions got extracted from
rangeEval
, and an annotation merge got hoisted.VectorAnd
,VectorOr
andVectorUnless
now return nilAnnotations
so they can be used directly as the evaluation function;VectorscalarBinop
should also returnAnnotations
but I'll leave that for another PR.Further work:
rangeEval
: two taking no expressions, one taking one, and one for function calls. Probably there are benefits to making each case less generic.rangeEvalBinOp
could compute series matches (via a map) once, and then use them over and over at each time step. This is not trivial as the same LHS can match different RHS as series come and go, but I think it will be a big win for large queries.rangeEvalBinOp
could implement the intended optimisation from Optimise VectorAnd for step invariant expression #9577 where one or other side is time-invariant.benchmark results
(
go test -timeout 50m -count=6 -run xxx -bench RangeQuery ./promql
)