Skip to content

PromQL: optimise joins where a subexpression is step-invariant #9368

@bboreham

Description

@bboreham

Proposal

In the blog post Introducing the '@' Modifier is this example:

rate(http_requests_total[1m]) # This acts like the actual selector.
  and
topk(5, rate(http_requests_total[1h] @ end())) # This acts like a ranking function which filters the selector.

As I read the current PromQL code, the engine will evaluate topk(5, rate(http_requests_total[1h] @ end())) just once, replicate those results out to the length of the query range, then go step by step calling VectorAnd on those results.
But, since the rhs data doesn't change, that wastes a lot of work building a map on every step.

Perhaps we can modify the binary-op implementations to allow for one side being constant.
(Both sides constant is already optimised).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions