Skip to content
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

MQE: subqueries #9664

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

MQE: subqueries #9664

wants to merge 15 commits into from

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Oct 18, 2024

What this PR does

This PR adds support for subqueries to MQE.

Our benchmarks show mild latency improvements in most cases over Prometheus' engine, and improvements in peak memory utilisation in most cases:

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/sum_over_time(a_1[10m:3m]),_instant_query-10                         156.0µ ± 4%   152.3µ ± 4%   -2.36% (p=0.015 n=6)
Query/sum_over_time(a_1[10m:3m]),_range_query_with_100_steps-10            165.6µ ± 2%   154.6µ ± 1%   -6.63% (p=0.002 n=6)
Query/sum_over_time(a_1[10m:3m]),_range_query_with_1000_steps-10           250.2µ ± 1%   245.1µ ± 2%   -2.03% (p=0.041 n=6)
Query/sum_over_time(a_100[10m:3m]),_instant_query-10                       1.116m ± 2%   1.075m ± 8%        ~ (p=0.065 n=6)
Query/sum_over_time(a_100[10m:3m]),_range_query_with_100_steps-10          1.882m ± 4%   1.691m ± 1%  -10.18% (p=0.002 n=6)
Query/sum_over_time(a_100[10m:3m]),_range_query_with_1000_steps-10         8.662m ± 0%   9.212m ± 1%   +6.36% (p=0.002 n=6)
Query/sum_over_time(a_2000[10m:3m]),_instant_query-10                      16.02m ± 1%   15.38m ± 1%   -3.99% (p=0.002 n=6)
Query/sum_over_time(a_2000[10m:3m]),_range_query_with_100_steps-10         30.11m ± 1%   26.48m ± 1%  -12.06% (p=0.002 n=6)
Query/sum_over_time(a_2000[10m:3m]),_range_query_with_1000_steps-10        160.5m ± 7%   171.7m ± 3%   +6.95% (p=0.015 n=6)
Query/sum_over_time(nh_1[10m:3m]),_instant_query-10                        202.3µ ± 1%   193.9µ ± 1%   -4.18% (p=0.002 n=6)
Query/sum_over_time(nh_1[10m:3m]),_range_query_with_100_steps-10           260.3µ ± 5%   246.1µ ± 2%   -5.45% (p=0.002 n=6)
Query/sum_over_time(nh_1[10m:3m]),_range_query_with_1000_steps-10          829.5µ ± 0%   800.1µ ± 2%   -3.54% (p=0.002 n=6)
Query/sum_over_time(nh_100[10m:3m]),_instant_query-10                      5.656m ± 3%   5.558m ± 3%   -1.73% (p=0.041 n=6)
Query/sum_over_time(nh_100[10m:3m]),_range_query_with_100_steps-10         10.78m ± 1%   10.32m ± 0%   -4.29% (p=0.002 n=6)
Query/sum_over_time(nh_100[10m:3m]),_range_query_with_1000_steps-10        62.86m ± 1%   58.10m ± 4%   -7.57% (p=0.002 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_instant_query-10                     105.3m ± 0%   103.4m ± 0%   -1.77% (p=0.002 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_range_query_with_100_steps-10        204.7m ± 1%   194.1m ± 5%   -5.21% (p=0.015 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_range_query_with_1000_steps-10        1.265 ± 3%    1.154 ± 1%   -8.81% (p=0.002 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_instant_query-10                    158.2µ ± 2%   150.4µ ± 2%   -4.93% (p=0.002 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_range_query_with_100_steps-10       169.8µ ± 2%   157.0µ ± 2%   -7.53% (p=0.002 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_range_query_with_1000_steps-10      279.2µ ± 1%   250.4µ ± 2%  -10.33% (p=0.002 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_instant_query-10                  1.135m ± 2%   1.071m ± 3%   -5.63% (p=0.002 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_range_query_with_100_steps-10     1.929m ± 1%   1.688m ± 3%  -12.50% (p=0.002 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_range_query_with_1000_steps-10    9.272m ± 1%   9.539m ± 1%   +2.88% (p=0.002 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_instant_query-10                 16.19m ± 4%   15.58m ± 3%   -3.75% (p=0.002 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_range_query_with_100_steps-10    31.18m ± 1%   27.01m ± 1%  -13.36% (p=0.002 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_range_query_with_1000_steps-10   183.2m ± 1%   178.0m ± 1%   -2.82% (p=0.002 n=6)
geomean                                                                    4.550m        4.329m        -4.87%

                                                                         │  Prometheus   │                Mimir                │
                                                                         │       B       │      B        vs base               │
Query/sum_over_time(a_1[10m:3m]),_instant_query-10                          73.68Mi ± 1%   73.67Mi ± 1%        ~ (p=0.784 n=6)
Query/sum_over_time(a_1[10m:3m]),_range_query_with_100_steps-10             73.23Mi ± 1%   73.53Mi ± 1%        ~ (p=0.132 n=6)
Query/sum_over_time(a_1[10m:3m]),_range_query_with_1000_steps-10            70.84Mi ± 1%   71.88Mi ± 1%   +1.48% (p=0.009 n=6)
Query/sum_over_time(a_100[10m:3m]),_instant_query-10                        67.51Mi ± 1%   66.95Mi ± 1%        ~ (p=0.132 n=6)
Query/sum_over_time(a_100[10m:3m]),_range_query_with_100_steps-10           67.80Mi ± 1%   67.02Mi ± 0%   -1.15% (p=0.002 n=6)
Query/sum_over_time(a_100[10m:3m]),_range_query_with_1000_steps-10          69.89Mi ± 1%   69.70Mi ± 1%        ~ (p=1.000 n=6)
Query/sum_over_time(a_2000[10m:3m]),_instant_query-10                       68.45Mi ± 2%   69.11Mi ± 1%        ~ (p=0.132 n=6)
Query/sum_over_time(a_2000[10m:3m]),_range_query_with_100_steps-10          75.21Mi ± 1%   77.66Mi ± 1%   +3.26% (p=0.002 n=6)
Query/sum_over_time(a_2000[10m:3m]),_range_query_with_1000_steps-10         133.3Mi ± 1%   127.6Mi ± 0%   -4.26% (p=0.002 n=6)
Query/sum_over_time(nh_1[10m:3m]),_instant_query-10                         78.29Mi ± 1%   78.73Mi ± 1%        ~ (p=0.394 n=6)
Query/sum_over_time(nh_1[10m:3m]),_range_query_with_100_steps-10            73.31Mi ± 1%   72.88Mi ± 0%        ~ (p=0.065 n=6)
Query/sum_over_time(nh_1[10m:3m]),_range_query_with_1000_steps-10           72.63Mi ± 1%   71.93Mi ± 1%   -0.97% (p=0.015 n=6)
Query/sum_over_time(nh_100[10m:3m]),_instant_query-10                       70.20Mi ± 1%   70.10Mi ± 1%        ~ (p=1.000 n=6)
Query/sum_over_time(nh_100[10m:3m]),_range_query_with_100_steps-10          73.68Mi ± 1%   73.95Mi ± 1%        ~ (p=0.180 n=6)
Query/sum_over_time(nh_100[10m:3m]),_range_query_with_1000_steps-10         120.0Mi ± 1%   121.8Mi ± 1%   +1.44% (p=0.004 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_instant_query-10                      76.34Mi ± 1%   73.81Mi ± 1%   -3.31% (p=0.002 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_range_query_with_100_steps-10         180.4Mi ± 1%   184.1Mi ± 1%   +2.09% (p=0.002 n=6)
Query/sum_over_time(nh_2000[10m:3m]),_range_query_with_1000_steps-10        630.1Mi ± 0%   726.8Mi ± 7%  +15.35% (p=0.002 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_instant_query-10                     73.16Mi ± 1%   73.48Mi ± 1%        ~ (p=0.485 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_range_query_with_100_steps-10        72.80Mi ± 2%   73.14Mi ± 1%        ~ (p=0.394 n=6)
Query/sum(sum_over_time(a_1[10m:3m])),_range_query_with_1000_steps-10       70.45Mi ± 0%   71.66Mi ± 1%   +1.72% (p=0.004 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_instant_query-10                   67.38Mi ± 2%   66.86Mi ± 1%        ~ (p=0.260 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_range_query_with_100_steps-10      67.45Mi ± 1%   66.66Mi ± 1%   -1.17% (p=0.026 n=6)
Query/sum(sum_over_time(a_100[10m:3m])),_range_query_with_1000_steps-10     69.45Mi ± 2%   66.91Mi ± 1%   -3.66% (p=0.002 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_instant_query-10                  69.12Mi ± 1%   68.40Mi ± 2%        ~ (p=0.065 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_range_query_with_100_steps-10     76.16Mi ± 1%   68.52Mi ± 2%  -10.03% (p=0.002 n=6)
Query/sum(sum_over_time(a_2000[10m:3m])),_range_query_with_1000_steps-10   132.88Mi ± 2%   71.20Mi ± 1%  -46.41% (p=0.002 n=6)
geomean                                                                     85.72Mi        83.71Mi        -2.34%

It is possible to improve the performance of the 1000 step cases, however to do this without affecting the performance of range vector selectors requires a bit of refactoring I'd prefer to do in a separate PR.

Which issue(s) this PR fixes or relates to

(none)

Checklist

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

@charleskorn charleskorn marked this pull request as ready for review October 18, 2024 03:32
@charleskorn charleskorn requested review from tacole02 and a team as code owners October 18, 2024 03:32
Copy link
Contributor

@tacole02 tacole02 left a comment

Choose a reason for hiding this comment

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

Looks good!

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