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

Simplify the last-value aggregate #4343

Merged
merged 4 commits into from
Jul 21, 2023
Merged

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Jul 19, 2023

Part of #4220

Instead of treating the returned *lastValue as an aggregator from newLastValue, just use the type directly to construct the Measure and ComputeAggregation functions returned from the Builder.

Accept a destination type for the underlying computeAggregation. This allows memory reuse for collections which adds a considerable optimization.

Simplify the integration testing of the last-value aggregate.

Update benchmarking.

Benchmarking

Measure

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric/internal/aggregate
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                │   old.txt   │              new.txt               │
                                │   sec/op    │   sec/op     vs base               │
LastValue/Int64/1/Measure-8       137.6n ± 1%   148.3n ± 4%  +7.82% (p=0.000 n=10)
LastValue/Int64/10/Measure-8      1.689µ ± 4%   1.686µ ± 3%       ~ (p=0.631 n=10)
LastValue/Int64/100/Measure-8     16.41µ ± 5%   17.31µ ± 2%  +5.47% (p=0.002 n=10)
LastValue/Float64/1/Measure-8     150.4n ± 4%   150.8n ± 5%       ~ (p=0.853 n=10)
LastValue/Float64/10/Measure-8    1.731µ ± 6%   1.770µ ± 3%       ~ (p=0.383 n=10)
LastValue/Float64/100/Measure-8   16.87µ ± 6%   16.89µ ± 5%       ~ (p=1.000 n=10)
geomean                           1.599µ        1.641µ       +2.59%

                                │   old.txt    │               new.txt               │
                                │     B/op     │    B/op     vs base                 │
LastValue/Int64/1/Measure-8       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Int64/10/Measure-8      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Int64/100/Measure-8     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/1/Measure-8     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/10/Measure-8    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/100/Measure-8   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                      ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                │   old.txt    │               new.txt               │
                                │  allocs/op   │ allocs/op   vs base                 │
LastValue/Int64/1/Measure-8       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Int64/10/Measure-8      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Int64/100/Measure-8     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/1/Measure-8     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/10/Measure-8    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
LastValue/Float64/100/Measure-8   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                      ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

ComputeAggregation

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric/internal/aggregate
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                           │   old.txt    │               new.txt               │
                                           │    sec/op    │   sec/op     vs base                │
LastValue/Int64/1/ComputeAggregation-8       387.0n ± 10%   269.0n ± 5%  -30.49% (p=0.000 n=10)
LastValue/Int64/10/ComputeAggregation-8      2.278µ ±  3%   1.657µ ± 6%  -27.28% (p=0.000 n=10)
LastValue/Int64/100/ComputeAggregation-8     19.79µ ±  3%   15.38µ ± 2%  -22.27% (p=0.000 n=10)
LastValue/Float64/1/ComputeAggregation-8     413.6n ± 10%   283.5n ± 6%  -31.46% (p=0.000 n=10)
LastValue/Float64/10/ComputeAggregation-8    2.325µ ±  7%   1.661µ ± 6%  -28.56% (p=0.000 n=10)
LastValue/Float64/100/ComputeAggregation-8   20.12µ ±  5%   15.39µ ± 5%  -23.53% (p=0.000 n=10)
geomean                                      2.639µ         1.917µ       -27.34%

                                           │   old.txt    │              new.txt               │
                                           │     B/op     │    B/op     vs base                │
LastValue/Int64/1/ComputeAggregation-8        120.00 ± 0%   24.00 ± 0%  -80.00% (p=0.000 n=10)
LastValue/Int64/10/ComputeAggregation-8      1048.00 ± 0%   24.00 ± 0%  -97.71% (p=0.000 n=10)
LastValue/Int64/100/ComputeAggregation-8     9752.00 ± 0%   24.00 ± 0%  -99.75% (p=0.000 n=10)
LastValue/Float64/1/ComputeAggregation-8      120.00 ± 0%   24.00 ± 0%  -80.00% (p=0.000 n=10)
LastValue/Float64/10/ComputeAggregation-8    1048.00 ± 0%   24.00 ± 0%  -97.71% (p=0.000 n=10)
LastValue/Float64/100/ComputeAggregation-8   9752.00 ± 0%   24.00 ± 0%  -99.75% (p=0.000 n=10)
geomean                                      1.045Ki        24.00       -97.76%

                                           │  old.txt   │              new.txt               │
                                           │ allocs/op  │ allocs/op   vs base                │
LastValue/Int64/1/ComputeAggregation-8       2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
LastValue/Int64/10/ComputeAggregation-8      2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
LastValue/Int64/100/ComputeAggregation-8     2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
LastValue/Float64/1/ComputeAggregation-8     2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
LastValue/Float64/10/ComputeAggregation-8    2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
LastValue/Float64/100/ComputeAggregation-8   2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
geomean                                      2.000        1.000       -50.00%

@MrAlias MrAlias added pkg:SDK Related to an SDK package area:metrics Part of OpenTelemetry Metrics labels Jul 19, 2023
@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #4343 (c2606e5) into main (a37cb05) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4343   +/-   ##
=====================================
  Coverage   83.4%   83.4%           
=====================================
  Files        184     184           
  Lines      14349   14360   +11     
=====================================
+ Hits       11975   11988   +13     
+ Misses      2147    2145    -2     
  Partials     227     227           
Impacted Files Coverage Δ
sdk/metric/internal/aggregate/aggregate.go 100.0% <100.0%> (ø)
sdk/metric/internal/aggregate/lastvalue.go 100.0% <100.0%> (ø)

... and 1 file with indirect coverage changes

Instead of treating the returned *lastValue as an aggregator from
newLastValue, just use the type directly to construct the Measure and
ComputeAggregation functions returned from the Builder.

Accept a destination type for the underlying computeAggregation. This
allows memory reuse for collections which adds a considerable
optimization.

Simplify the integration testing of the last-value aggregate.

Update benchmarking.
@MrAlias MrAlias added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jul 19, 2023
@MrAlias MrAlias marked this pull request as ready for review July 19, 2023 23:18
@MrAlias MrAlias changed the title Simplify the last-value aggregate path Simplify the last-value aggregate Jul 19, 2023
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Nice performance improvement. I just left minor comments. It may be good if you take a look at #4345 as it touches the same codebase.

sdk/metric/internal/aggregate/aggregate.go Show resolved Hide resolved
sdk/metric/internal/aggregate/aggregate.go Outdated Show resolved Hide resolved
Co-authored-by: Robert Pająk <pellared@hotmail.com>
@pellared pellared merged commit cbc5890 into open-telemetry:main Jul 21, 2023
@MrAlias MrAlias deleted the simp-lv branch July 21, 2023 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics pkg:SDK Related to an SDK package Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants