1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-31 21:55:32 +02:00
Sam Xie 3429e15b9a
Revert Cleanup interaction of exemplar and aggregation ()
Topic: 

This reverts commit 8041156518ee2f31ec9b36852fdc29f093d0f468 (PR: )
due to the performance degradation found by Benchmarks CI
https://github.com/open-telemetry/opentelemetry-go/actions/runs/11447364022/job/31848519243

Here is the benchmark test on my machine:

```
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/metric
                                       │   old.txt   │                new.txt                 │
                                       │   sec/op    │    sec/op     vs base                  │
Instrument/instrumentImpl/aggregate-10   3.378µ ± 3%   49.366µ ± 1%  +1361.40% (p=0.000 n=10)
Instrument/observable/observe-10         2.288µ ± 2%   37.791µ ± 1%  +1551.73% (p=0.000 n=10)
geomean                                  2.780µ         43.19µ       +1453.65%

                                       │   old.txt    │                 new.txt                 │
                                       │     B/op     │     B/op       vs base                  │
Instrument/instrumentImpl/aggregate-10   1.245Ki ± 1%   22.363Ki ± 0%  +1696.08% (p=0.000 n=10)
Instrument/observable/observe-10           823.0 ± 1%    17432.5 ± 0%  +2018.17% (p=0.000 n=10)
geomean                                  1.000Ki         19.51Ki       +1850.48%

                                       │  old.txt   │                new.txt                │
                                       │ allocs/op  │  allocs/op   vs base                  │
Instrument/instrumentImpl/aggregate-10   1.000 ± 0%   21.000 ± 0%  +2000.00% (p=0.000 n=10)
Instrument/observable/observe-10         1.000 ± 0%   16.000 ± 0%  +1500.00% (p=0.000 n=10)
```
2024-10-23 10:48:07 -07:00

78 lines
1.7 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package metric
import (
"context"
"testing"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/internal/aggregate"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)
func BenchmarkInstrument(b *testing.B) {
attr := func(id int) attribute.Set {
return attribute.NewSet(
attribute.String("user", "Alice"),
attribute.Bool("admin", true),
attribute.Int("id", id),
)
}
b.Run("instrumentImpl/aggregate", func(b *testing.B) {
build := aggregate.Builder[int64]{}
var meas []aggregate.Measure[int64]
build.Temporality = metricdata.CumulativeTemporality
in, _ := build.LastValue()
meas = append(meas, in)
build.Temporality = metricdata.DeltaTemporality
in, _ = build.LastValue()
meas = append(meas, in)
build.Temporality = metricdata.CumulativeTemporality
in, _ = build.Sum(true)
meas = append(meas, in)
build.Temporality = metricdata.DeltaTemporality
in, _ = build.Sum(true)
meas = append(meas, in)
inst := int64Inst{measures: meas}
ctx := context.Background()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
inst.aggregate(ctx, int64(i), attr(i))
}
})
b.Run("observable/observe", func(b *testing.B) {
build := aggregate.Builder[int64]{}
var meas []aggregate.Measure[int64]
in, _ := build.PrecomputedLastValue()
meas = append(meas, in)
build.Temporality = metricdata.CumulativeTemporality
in, _ = build.Sum(true)
meas = append(meas, in)
build.Temporality = metricdata.DeltaTemporality
in, _ = build.Sum(true)
meas = append(meas, in)
o := observable[int64]{measures: meas}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
o.observe(int64(i), attr(i))
}
})
}