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

execution: reorganize function operators #285

Merged

Conversation

MichaHoffmann
Copy link
Contributor

@MichaHoffmann MichaHoffmann commented Jun 5, 2023

  • distinguish between functions taking an instant vector and functions taking a range vector
  • since scan does not depend on function anymore we can hide a couple structs and functions
  • some cleanup in execution.go

@MichaHoffmann MichaHoffmann force-pushed the mhoffm-reorganize-function-operators branch 4 times, most recently from 3108c8a to 48cf5cb Compare June 7, 2023 19:02
Copy link
Collaborator

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

I love the cleanup, awesome work !

StepTime int64
SelectRange int64
ScalarPoints []float64
Offset int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to pass Offset and SelectRange via a clojure when creating the function? These values should be constant and do not change between steps, so we might get a small speed up if there are less arguments to put on the stack before the function call.

The arguments are also optional for most functions so there might be an unnecessary overhead for something like sum_over_time.

},
"xincrease": func(f functionArgs) sample {
if len(f.Samples) == 0 {
return invalidSample
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should remove invalidSample in favour of an ok return argument to indicate whether the function returns any value. The return args would then be float64, *histogram.FloatHistogram, bool. We also don't need the timestamp of the result sample since that comes from the step itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that sounds much better! thanks ill do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! it has some effect

on main:

RangeQuery/clamp-8                                           632.5m ± ∞ ¹    102.5m ± ∞ ¹   -83.79% (p=0.008 n=5)

vs PR

RangeQuery/clamp-8                                          631.62m ± ∞ ¹    85.65m ± ∞ ¹   -86.44% (p=0.008 n=5)

execution/scan/matrix_selector.go Outdated Show resolved Hide resolved
)

var InvalidSample = Sample{T: -1, F: 0}
var invalidSample = sample{T: -1, F: 0}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here I would also consider removing invalidSample in favour of 3 return arguments and dropping the timestamp.

MetricAppearedTs *int64
type functionArgs struct {
Samples []sample
StepTime int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to use this parameter in functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah no, we only need it in range functions i think, not removing it was an oversight

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah its somewhat used in the time related functions; most of the time not though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i propose that we keep it for now and maybe handle the time based functions with a special sub operator here, wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i went ahead and removed it too because it would complicate the date functions. i now introduced noArgs and withArgs variants of them and got rid of step time most of the functions that way.

@MichaHoffmann MichaHoffmann force-pushed the mhoffm-reorganize-function-operators branch 6 times, most recently from 2a9c4ca to e39a8da Compare June 10, 2023 09:28
@MichaHoffmann MichaHoffmann force-pushed the mhoffm-reorganize-function-operators branch from e39a8da to 1750741 Compare July 7, 2023 09:41
Signed-off-by: Filip Petkovski <[email protected]>
@fpetkovski fpetkovski force-pushed the mhoffm-reorganize-function-operators branch from 9db0431 to 270c534 Compare July 7, 2023 10:07
Copy link
Collaborator

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good now.

There was a regression in range selectors since the PR changed IsExtFunction to use a map instead of comparing constants. That should now be fixed by doing the comparison once when creating the operator.

Signed-off-by: Filip Petkovski <[email protected]>
@fpetkovski fpetkovski force-pushed the mhoffm-reorganize-function-operators branch from c2ae5b7 to ef8e932 Compare July 7, 2023 10:31
@fpetkovski
Copy link
Collaborator

Benchmark results against main

benchstat benchmarks/main.out benchmarks/new.out      
name                                                  old time/op    new time/op    delta
RangeQuery/vector_selector-8                            14.0ms ± 0%    19.5ms ±29%     ~     (p=0.151 n=5+5)
RangeQuery/sum-8                                        10.0ms ± 0%     9.8ms ± 0%   -2.21%  (p=0.008 n=5+5)
RangeQuery/sum_by_pod-8                                 13.9ms ± 0%    13.8ms ± 1%     ~     (p=0.556 n=4+5)
RangeQuery/topk-8                                       11.0ms ± 5%    10.5ms ± 0%   -4.51%  (p=0.008 n=5+5)
RangeQuery/bottomk-8                                    11.0ms ± 5%    10.4ms ± 0%   -5.41%  (p=0.008 n=5+5)
RangeQuery/rate-8                                       20.0ms ± 4%    18.8ms ± 1%   -5.86%  (p=0.008 n=5+5)
RangeQuery/sum_rate-8                                   17.5ms ± 1%    16.5ms ± 1%   -5.64%  (p=0.008 n=5+5)
RangeQuery/sum_by_rate-8                                20.3ms ± 1%    19.3ms ± 0%   -5.03%  (p=0.008 n=5+5)
RangeQuery/quantile_with_variable_parameter-8           24.0ms ± 2%    23.4ms ± 1%   -2.55%  (p=0.016 n=5+5)
RangeQuery/binary_operation_with_one_to_one-8           13.2ms ± 4%    12.9ms ± 0%     ~     (p=0.056 n=5+5)
RangeQuery/binary_operation_with_many_to_one-8          28.0ms ± 0%    27.9ms ± 1%     ~     (p=0.730 n=4+5)
RangeQuery/binary_operation_with_vector_and_scalar-8    19.3ms ± 1%    19.2ms ± 1%     ~     (p=0.548 n=5+5)
RangeQuery/unary_negation-8                             14.3ms ± 5%    14.4ms ± 2%     ~     (p=0.421 n=5+5)
RangeQuery/vector_and_scalar_comparison-8               20.0ms ± 3%    19.6ms ± 1%     ~     (p=0.095 n=5+5)
RangeQuery/positive_offset_vector-8                     13.3ms ± 3%    13.0ms ± 4%     ~     (p=0.222 n=5+5)
RangeQuery/at_modifier_-8                               10.0ms ± 3%     9.9ms ± 6%     ~     (p=0.310 n=5+5)
RangeQuery/at_modifier_with_positive_offset_vector-8    9.75ms ± 4%    9.50ms ± 0%   -2.57%  (p=0.016 n=5+4)
RangeQuery/clamp-8                                      19.8ms ± 2%    17.4ms ± 0%  -12.08%  (p=0.016 n=5+4)
RangeQuery/clamp_min-8                                  18.3ms ± 1%    16.3ms ± 0%  -11.08%  (p=0.008 n=5+5)
RangeQuery/complex_func_query-8                         26.0ms ± 1%    23.4ms ± 1%  -10.00%  (p=0.008 n=5+5)
RangeQuery/func_within_func_query-8                     20.2ms ± 0%    19.2ms ± 1%   -4.91%  (p=0.008 n=5+5)
RangeQuery/aggr_within_func_query-8                     20.2ms ± 0%    19.2ms ± 2%   -5.14%  (p=0.008 n=5+5)
RangeQuery/histogram_quantile-8                         93.7ms ± 0%    94.3ms ± 0%   +0.61%  (p=0.008 n=5+5)
RangeQuery/sort-8                                       13.8ms ± 0%    13.8ms ± 1%     ~     (p=0.730 n=4+5)
RangeQuery/sort_desc-8                                  13.8ms ± 2%    13.8ms ± 1%     ~     (p=0.690 n=5+5)
RangeQuery/absent_and_exists-8                          10.1ms ± 1%     9.7ms ± 0%   -4.08%  (p=0.016 n=4+5)
RangeQuery/absent_and_doesnt_exist-8                     248µs ± 2%     246µs ± 5%     ~     (p=0.548 n=5+5)
NativeHistograms/selector-8                              135ms ± 2%     138ms ± 2%     ~     (p=0.056 n=5+5)
NativeHistograms/sum-8                                   195ms ± 1%     196ms ± 1%     ~     (p=0.151 n=5+5)
NativeHistograms/rate-8                                  455ms ± 1%     457ms ± 1%     ~     (p=0.556 n=4+5)
NativeHistograms/sum_rate-8                              495ms ± 9%     498ms ± 8%     ~     (p=1.000 n=5+5)
NativeHistograms/histogram_sum-8                         376ms ± 1%     372ms ± 1%   -1.18%  (p=0.016 n=5+5)
NativeHistograms/histogram_count-8                       388ms ± 4%     369ms ± 1%   -4.91%  (p=0.008 n=5+5)
NativeHistograms/histogram_quantile-8                    205ms ± 3%     197ms ± 1%   -3.72%  (p=0.016 n=5+5)
NativeHistograms/histogram_scalar_binop-8                315ms ± 2%     311ms ± 3%     ~     (p=0.222 n=5+5)

name                                                  old alloc/op   new alloc/op   delta
RangeQuery/vector_selector-8                            28.2MB ± 0%    28.2MB ± 0%   +0.09%  (p=0.008 n=5+5)
RangeQuery/sum-8                                        8.05MB ± 0%    8.05MB ± 0%     ~     (p=0.421 n=5+5)
RangeQuery/sum_by_pod-8                                 18.7MB ± 0%    18.7MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/topk-8                                       9.80MB ± 2%    9.61MB ± 0%   -1.88%  (p=0.016 n=5+5)
RangeQuery/bottomk-8                                    9.78MB ± 3%    9.62MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/rate-8                                       30.3MB ± 0%    30.4MB ± 0%   +0.40%  (p=0.008 n=5+5)
RangeQuery/sum_rate-8                                   10.5MB ± 0%    10.6MB ± 0%   +0.56%  (p=0.008 n=5+5)
RangeQuery/sum_by_rate-8                                20.0MB ± 0%    20.1MB ± 0%     ~     (p=0.095 n=5+5)
RangeQuery/quantile_with_variable_parameter-8           34.0MB ± 0%    34.0MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/binary_operation_with_one_to_one-8           18.5MB ± 0%    18.5MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/binary_operation_with_many_to_one-8          46.5MB ± 0%    46.5MB ± 0%   -0.02%  (p=0.008 n=5+5)
RangeQuery/binary_operation_with_vector_and_scalar-8    31.3MB ± 0%    31.2MB ± 0%     ~     (p=0.095 n=5+5)
RangeQuery/unary_negation-8                             29.3MB ± 0%    29.3MB ± 0%     ~     (p=0.841 n=5+5)
RangeQuery/vector_and_scalar_comparison-8               30.9MB ± 0%    30.8MB ± 0%   -0.34%  (p=0.032 n=5+5)
RangeQuery/positive_offset_vector-8                     27.3MB ± 0%    27.3MB ± 0%     ~     (p=0.548 n=5+5)
RangeQuery/at_modifier_-8                               23.9MB ± 0%    23.9MB ± 0%     ~     (p=0.841 n=5+5)
RangeQuery/at_modifier_with_positive_offset_vector-8    23.7MB ± 0%    23.7MB ± 0%   +0.01%  (p=0.032 n=5+5)
RangeQuery/clamp-8                                      28.7MB ± 0%    28.6MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/clamp_min-8                                  28.6MB ± 0%    28.6MB ± 0%     ~     (p=0.310 n=5+5)
RangeQuery/complex_func_query-8                         31.7MB ± 0%    31.7MB ± 0%     ~     (p=1.000 n=5+5)
RangeQuery/func_within_func_query-8                     31.0MB ± 0%    30.8MB ± 0%   -0.57%  (p=0.008 n=5+5)
RangeQuery/aggr_within_func_query-8                     31.0MB ± 0%    30.8MB ± 0%   -0.63%  (p=0.008 n=5+5)
RangeQuery/histogram_quantile-8                         50.2MB ± 0%    50.2MB ± 0%     ~     (p=0.222 n=5+5)
RangeQuery/sort-8                                       28.2MB ± 0%    28.3MB ± 0%     ~     (p=0.095 n=5+5)
RangeQuery/sort_desc-8                                  28.2MB ± 0%    28.2MB ± 0%     ~     (p=0.151 n=5+5)
RangeQuery/absent_and_exists-8                          7.97MB ± 0%    7.85MB ± 0%   -1.47%  (p=0.016 n=4+5)
RangeQuery/absent_and_doesnt_exist-8                     525kB ± 0%     525kB ± 0%     ~     (p=1.000 n=5+5)
NativeHistograms/selector-8                              451MB ± 0%     451MB ± 0%   +0.02%  (p=0.016 n=5+5)
NativeHistograms/sum-8                                   618MB ± 0%     618MB ± 0%     ~     (p=0.548 n=5+5)
NativeHistograms/rate-8                                 1.40GB ± 0%    1.40GB ± 0%     ~     (p=0.421 n=5+5)
NativeHistograms/sum_rate-8                             1.56GB ± 0%    1.56GB ± 0%     ~     (p=1.000 n=5+5)
NativeHistograms/histogram_sum-8                         452MB ± 0%     452MB ± 0%     ~     (p=0.421 n=5+5)
NativeHistograms/histogram_count-8                       452MB ± 0%     452MB ± 0%     ~     (p=0.222 n=5+5)
NativeHistograms/histogram_quantile-8                    618MB ± 0%     618MB ± 0%     ~     (p=0.690 n=5+5)
NativeHistograms/histogram_scalar_binop-8                798MB ± 0%     798MB ± 0%     ~     (p=1.000 n=5+5)

name                                                  old allocs/op  new allocs/op  delta
RangeQuery/vector_selector-8                             91.7k ± 0%     91.7k ± 0%   -0.03%  (p=0.016 n=5+5)
RangeQuery/sum-8                                         74.0k ± 0%     74.0k ± 0%   -0.06%  (p=0.008 n=5+5)
RangeQuery/sum_by_pod-8                                   172k ± 0%      172k ± 0%   -0.02%  (p=0.008 n=5+5)
RangeQuery/topk-8                                        94.1k ± 0%     92.9k ± 0%   -1.31%  (p=0.008 n=5+5)
RangeQuery/bottomk-8                                     91.9k ± 0%     93.2k ± 0%   +1.48%  (p=0.008 n=5+5)
RangeQuery/rate-8                                         116k ± 0%      116k ± 0%     ~     (p=0.738 n=5+5)
RangeQuery/sum_rate-8                                     101k ± 0%      101k ± 0%   -0.03%  (p=0.008 n=5+5)
RangeQuery/sum_by_rate-8                                  198k ± 0%      198k ± 0%   -0.02%  (p=0.008 n=5+5)
RangeQuery/quantile_with_variable_parameter-8             517k ± 0%      517k ± 0%   -0.02%  (p=0.008 n=5+5)
RangeQuery/binary_operation_with_one_to_one-8            74.4k ± 0%     74.3k ± 0%   -0.16%  (p=0.008 n=5+5)
RangeQuery/binary_operation_with_many_to_one-8            147k ± 0%      146k ± 0%   -0.11%  (p=0.008 n=5+5)
RangeQuery/binary_operation_with_vector_and_scalar-8     98.9k ± 0%     98.8k ± 0%   -0.06%  (p=0.008 n=5+5)
RangeQuery/unary_negation-8                               101k ± 0%      101k ± 0%   -0.04%  (p=0.008 n=5+5)
RangeQuery/vector_and_scalar_comparison-8                92.9k ± 0%     92.8k ± 0%   -0.10%  (p=0.008 n=5+5)
RangeQuery/positive_offset_vector-8                      77.2k ± 0%     77.1k ± 0%   -0.05%  (p=0.016 n=5+5)
RangeQuery/at_modifier_-8                                63.3k ± 0%     63.3k ± 0%   -0.02%  (p=0.029 n=4+4)
RangeQuery/at_modifier_with_positive_offset_vector-8     57.3k ± 0%     57.3k ± 0%   -0.03%  (p=0.029 n=4+4)
RangeQuery/clamp-8                                       98.5k ± 0%     98.5k ± 0%   -0.07%  (p=0.008 n=5+5)
RangeQuery/clamp_min-8                                   98.1k ± 0%     98.1k ± 0%   -0.04%  (p=0.008 n=5+5)
RangeQuery/complex_func_query-8                           109k ± 0%      109k ± 0%   -0.04%  (p=0.008 n=5+5)
RangeQuery/func_within_func_query-8                       123k ± 0%      122k ± 0%   -0.16%  (p=0.008 n=5+5)
RangeQuery/aggr_within_func_query-8                       123k ± 0%      122k ± 0%   -0.17%  (p=0.008 n=5+5)
RangeQuery/histogram_quantile-8                           578k ± 0%      578k ± 0%   -0.02%  (p=0.008 n=5+5)
RangeQuery/sort-8                                        91.7k ± 0%     91.7k ± 0%   -0.03%  (p=0.016 n=5+5)
RangeQuery/sort_desc-8                                   91.7k ± 0%     91.7k ± 0%   -0.04%  (p=0.008 n=5+5)
RangeQuery/absent_and_exists-8                           73.5k ± 0%     73.4k ± 0%   -0.12%  (p=0.016 n=4+5)
RangeQuery/absent_and_doesnt_exist-8                     2.42k ± 0%     2.42k ± 0%     ~     (p=1.000 n=5+5)
NativeHistograms/selector-8                              5.27M ± 0%     5.27M ± 0%   +0.00%  (p=0.008 n=5+5)
NativeHistograms/sum-8                                   6.70M ± 0%     6.70M ± 0%     ~     (p=1.000 n=5+5)
NativeHistograms/rate-8                                  22.7M ± 0%     22.7M ± 0%     ~     (p=0.548 n=5+5)
NativeHistograms/sum_rate-8                              24.1M ± 0%     24.1M ± 0%     ~     (p=0.421 n=5+5)
NativeHistograms/histogram_sum-8                         5.28M ± 0%     5.28M ± 0%     ~     (p=0.222 n=5+5)
NativeHistograms/histogram_count-8                       5.28M ± 0%     5.28M ± 0%     ~     (p=0.548 n=5+5)
NativeHistograms/histogram_quantile-8                    6.71M ± 0%     6.71M ± 0%     ~     (p=0.841 n=5+5)
NativeHistograms/histogram_scalar_binop-8                10.3M ± 0%     10.3M ± 0%     ~     (p=0.421 n=5+5)

@fpetkovski fpetkovski merged commit b807d13 into thanos-io:main Jul 7, 2023
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