Skip to content

Conversation

charleskorn
Copy link
Contributor

What this PR does

This PR adds support in MQE for sort and sort_desc.

Performance compared to Prometheus' engine is slightly better, and peak memory consumption is the same:

goos: darwin
goarch: arm64
pkg: github.com/grafana/mimir/pkg/streamingpromql/benchmarks
cpu: Apple M1 Pro
                                     │ Prometheus  │               Mimir               │
                                     │   sec/op    │   sec/op     vs base              │
Query/sort(a_1),_instant_query-10      146.4µ ± 2%   142.4µ ± 2%  -2.71% (p=0.009 n=6)
Query/sort(a_100),_instant_query-10    839.6µ ± 1%   798.6µ ± 2%  -4.88% (p=0.002 n=6)
Query/sort(a_2000),_instant_query-10   11.14m ± 1%   10.78m ± 1%  -3.18% (p=0.002 n=6)
geomean                                1.110m        1.070m       -3.59%

                                     │  Prometheus  │               Mimir                │
                                     │      B       │      B        vs base              │
Query/sort(a_1),_instant_query-10      66.26Mi ± 1%   65.87Mi ± 1%       ~ (p=0.310 n=6)
Query/sort(a_100),_instant_query-10    61.38Mi ± 1%   60.78Mi ± 1%       ~ (p=0.128 n=6)
Query/sort(a_2000),_instant_query-10   62.58Mi ± 1%   62.93Mi ± 1%       ~ (p=0.143 n=6)
geomean                                63.37Mi        63.16Mi       -0.33%

Given sort and sort_desc only apply to instant queries and we have to load the entire set of data into memory to sort it, there's not much room for improvement over Prometheus' engine.

Which issue(s) this PR fixes or relates to

#10067

Checklist

  • Tests updated.
  • [n/a] Documentation added.
  • [covered by Mimir Query Engine #10067] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • [n/a] about-versioning.md updated with experimental features.

This was referenced Jan 21, 2025
@charleskorn charleskorn marked this pull request as ready for review January 21, 2025 04:34
@charleskorn charleskorn requested a review from a team as a code owner January 21, 2025 04:34
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just a couple of small things

test_metric{case="histogram with +Inf"} {{count:0 sum:Inf}} {{count:0 sum:Inf}} {{count:0 sum:Inf}} {{count:0 sum:Inf}} {{count:0 sum:Inf}}
test_metric{case="histogram with -Inf"} {{count:0 sum:-Inf}} {{count:0 sum:-Inf}} {{count:0 sum:-Inf}} {{count:0 sum:-Inf}} {{count:0 sum:-Inf}}

# Sorting of identical values is not stable, so we exclude those from these test cases and check them below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there why there's no gauntlet? Otherwise we should add these there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, and also the fact that sort / sort_desc only apply to instant queries, but the gauntlet only does range queries.

@charleskorn charleskorn marked this pull request as draft February 4, 2025 23:09
@charleskorn charleskorn marked this pull request as ready for review February 4, 2025 23:38
@charleskorn charleskorn requested a review from jhesketh February 4, 2025 23:54
@charleskorn charleskorn merged commit d0ed3eb into main Feb 5, 2025
28 checks passed
@charleskorn charleskorn deleted the charleskorn/mqe-sort branch February 5, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants