Skip to content

Commit d6beb6a

Browse files
authored
Concurrent performance improvements; add performance settings field; support IgnoreCollisions (#384)
1 parent 1fb5140 commit d6beb6a

File tree

15 files changed

+320
-71
lines changed

15 files changed

+320
-71
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## Unreleased
1010

11+
## [1.13.1](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.13.1) - 2022-02-15)
12+
13+
- Adds performance improvements for concurrent use of synchronous
14+
instruments. [#384](https://github.com/lightstep/otel-launcher-go/pull/384)
15+
- Adds `WithPerformance()` and `IgnoreCollisions` setting which offers
16+
around 10% faster operations in exchange for safety and correctness. This
17+
setting is off by default. [#384](https://github.com/lightstep/otel-launcher-go/pull/384)
18+
1119
## [1.13.0](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.13.0) - 2022-02-15)
1220

1321
- Updates OTel-Go version dependencies to `[email protected]`, `[email protected]`,

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.13.0
1+
1.13.1

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/lightstep/otel-launcher-go
33
go 1.18
44

55
require (
6-
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.13.0
7-
github.com/lightstep/otel-launcher-go/pipelines v1.13.0
6+
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.13.1
7+
github.com/lightstep/otel-launcher-go/pipelines v1.13.1
88
github.com/sethvargo/go-envconfig v0.8.3
99
github.com/stretchr/testify v1.8.1
1010
go.opentelemetry.io/otel v1.12.0
@@ -23,7 +23,7 @@ require (
2323
github.com/golang/protobuf v1.5.2 // indirect
2424
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
2525
github.com/lightstep/go-expohisto v1.0.0 // indirect
26-
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.13.0 // indirect
26+
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.13.1 // indirect
2727
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
2828
github.com/pmezard/go-difflib v1.0.0 // indirect
2929
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect

launcher/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package launcher
1616

17-
const version = "1.13.0"
17+
const version = "1.13.1"

lightstep/sdk/metric/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,15 @@ For example, to configure a synchronous Gauge:
122122
)
123123
```
124124

125+
126+
### Performance settings
127+
128+
The `WithPerformance()` option supports control over performance
129+
settings.
130+
131+
#### IgnoreCollisions
132+
133+
With `IgnoreCollisions` set to true, the SDK will ignore fingerprint
134+
collisions and bypass a safety mechanism that ensures correctness in
135+
spite of fingerprint collisions in the fast path for synchronous
136+
instruments.

lightstep/sdk/metric/benchmark_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ import (
1919
"testing"
2020

2121
"github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/data"
22+
"github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/sdkinstrument"
2223
"github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/view"
2324
"go.opentelemetry.io/otel/attribute"
2425
)
2526

27+
var unsafePerf = WithPerformance(sdkinstrument.Performance{
28+
IgnoreCollisions: true,
29+
})
30+
2631
// Tested prior to 0.11.0 release
2732
// goos: darwin
2833
// goarch: arm64
@@ -64,6 +69,19 @@ func BenchmarkCounterAddOneAttr(b *testing.B) {
6469
}
6570
}
6671

72+
func BenchmarkCounterAddOneAttrUnsafe(b *testing.B) {
73+
ctx := context.Background()
74+
rdr := NewManualReader("bench")
75+
provider := NewMeterProvider(WithReader(rdr), unsafePerf)
76+
b.ReportAllocs()
77+
78+
cntr, _ := provider.Meter("test").Int64Counter("hello")
79+
80+
for i := 0; i < b.N; i++ {
81+
cntr.Add(ctx, 1, attribute.String("K", "V"))
82+
}
83+
}
84+
6785
func BenchmarkCounterAddOneInvalidAttr(b *testing.B) {
6886
ctx := context.Background()
6987
rdr := NewManualReader("bench")
@@ -90,6 +108,19 @@ func BenchmarkCounterAddManyAttrs(b *testing.B) {
90108
}
91109
}
92110

111+
func BenchmarkCounterAddManyAttrsUnsafe(b *testing.B) {
112+
ctx := context.Background()
113+
rdr := NewManualReader("bench")
114+
provider := NewMeterProvider(WithReader(rdr), unsafePerf)
115+
b.ReportAllocs()
116+
117+
cntr, _ := provider.Meter("test").Int64Counter("hello")
118+
119+
for i := 0; i < b.N; i++ {
120+
cntr.Add(ctx, 1, attribute.Int("K", i))
121+
}
122+
}
123+
93124
func BenchmarkCounterAddManyInvalidAttrs(b *testing.B) {
94125
ctx := context.Background()
95126
rdr := NewManualReader("bench")
@@ -103,6 +134,19 @@ func BenchmarkCounterAddManyInvalidAttrs(b *testing.B) {
103134
}
104135
}
105136

137+
func BenchmarkCounterAddManyInvalidAttrsUnsafe(b *testing.B) {
138+
ctx := context.Background()
139+
rdr := NewManualReader("bench")
140+
provider := NewMeterProvider(WithReader(rdr), unsafePerf)
141+
b.ReportAllocs()
142+
143+
cntr, _ := provider.Meter("test").Int64Counter("hello")
144+
145+
for i := 0; i < b.N; i++ {
146+
cntr.Add(ctx, 1, attribute.Int("", i), attribute.Int("K", i))
147+
}
148+
}
149+
106150
func BenchmarkCounterAddManyFilteredAttrs(b *testing.B) {
107151
ctx := context.Background()
108152
rdr := NewManualReader("bench")

lightstep/sdk/metric/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package metric // import "github.com/lightstep/otel-launcher-go/lightstep/sdk/metric"
1616

1717
import (
18+
"github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/sdkinstrument"
1819
"github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/view"
1920
"go.opentelemetry.io/otel"
2021
"go.opentelemetry.io/otel/sdk/resource"
@@ -32,6 +33,9 @@ type config struct {
3233
// views is a slice of *Views instances corresponding with readers.
3334
// the i'th views applies to the i'th reader.
3435
views []*view.Views
36+
37+
// performance settings
38+
performance sdkinstrument.Performance
3539
}
3640

3741
// Option applies a configuration option value to a MeterProvider.
@@ -68,3 +72,11 @@ func WithReader(r Reader, opts ...view.Option) Option {
6872
return cfg
6973
})
7074
}
75+
76+
// WithPerformance supports modifying performance settings.
77+
func WithPerformance(perf sdkinstrument.Performance) Option {
78+
return optionFunction(func(cfg config) config {
79+
cfg.performance = perf
80+
return cfg
81+
})
82+
}

lightstep/sdk/metric/example/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/example
33
go 1.18
44

55
require (
6-
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.13.0
6+
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.13.1
77
github.com/lightstep/otel-launcher-go/pipelines v1.8.0
88
go.opentelemetry.io/proto/otlp v0.19.0
99
)

lightstep/sdk/metric/internal/asyncstate/async.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ func NewState(pipe int) *State {
7979
}
8080
}
8181

82-
// New returns a new Instrument; this compiles individual
82+
// New returns a new Observer; this compiles individual
8383
// instruments for each reader.
84-
func New(desc sdkinstrument.Descriptor, opaque interface{}, compiled pipeline.Register[viewstate.Instrument]) *Observer {
84+
func New(desc sdkinstrument.Descriptor, _ sdkinstrument.Performance, opaque interface{}, compiled pipeline.Register[viewstate.Instrument]) *Observer {
8585
// Note: we return a non-nil instrument even when all readers
8686
// disabled the instrument. This ensures that certain error
8787
// checks still work (wrong meter, wrong callback, etc).
88+
//
89+
// Note: performance settings are not used because async
90+
// instruments do not use fingerprinting so IgnoreCollisions is
91+
// meaningless.
8892
return &Observer{
8993
opaque: opaque,
9094
descriptor: desc,

lightstep/sdk/metric/internal/asyncstate/async_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ var (
5353
Last: middleTime,
5454
Now: endTime,
5555
}
56+
57+
ignorePerf = sdkinstrument.Performance{
58+
IgnoreCollisions: false,
59+
}
5660
)
5761

5862
type testSDK struct {
@@ -106,12 +110,12 @@ type floatObserver struct {
106110

107111
func testIntObserver(tsdk *testSDK, name string, ik sdkinstrument.Kind) intObserver {
108112
desc := test.Descriptor(name, ik, number.Int64Kind)
109-
return intObserver{Observer: New(desc, tsdk, tsdk.compile(desc))}
113+
return intObserver{Observer: New(desc, ignorePerf, tsdk, tsdk.compile(desc))}
110114
}
111115

112116
func testFloatObserver(tsdk *testSDK, name string, ik sdkinstrument.Kind) floatObserver {
113117
desc := test.Descriptor(name, ik, number.Float64Kind)
114-
return floatObserver{Observer: New(desc, tsdk, tsdk.compile(desc))}
118+
return floatObserver{Observer: New(desc, ignorePerf, tsdk, tsdk.compile(desc))}
115119
}
116120

117121
func nopCB(context.Context, metric.Observer) error {

0 commit comments

Comments
 (0)