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

Fix batch processor metrics reorder, improve performance #3034

Merged
merged 1 commit into from
May 5, 2021

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Apr 27, 2021

Benchmarks Before:

goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    6660	    170653 ns/op	  182889 B/op	    3309 allocs/op
PASS

Process finished with the exit code 0

Benchmarks After:

goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    7858	    134259 ns/op	  141881 B/op	    2596 allocs/op
PASS

Process finished with the exit code 0

Benchmarks Reference Clone:

goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkCloneMetrics
BenchmarkCloneMetrics-16    	    8726	    127948 ns/op	  137816 B/op	    2503 allocs/op
PASS

Process finished with the exit code 0

Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com


// If possible to move all metrics do that.
srcMetricsLen := srcIm.Metrics().Len()
if size-totalCopiedMetrics >= srcMetricsLen {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might read a little cleaner:

Suggested change
if size-totalCopiedMetrics >= srcMetricsLen {
remainingSpace := size - totalCopiedMetrics
if srcMetricsLen <= remainingSpace {
totalCopiedMetrics += srcMetricsLen

processor/batchprocessor/splitmetrics.go Outdated Show resolved Hide resolved
srcIm.Metrics().RemoveIf(func(srcMetric pdata.Metric) bool {
// If we are done skip everything else.
if totalCopiedMetrics == size {
return false
Copy link
Member

Choose a reason for hiding this comment

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

Nit: it would be nicer if RemoveIf had a way to break the iteration. In this case we will continue to iterate but there is no need, it is pointless. (BTW, RemoveAt would allow this :-) )

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, was thinking to actually return a slice of pdata to benefit of the fact that we iterate over all anyway, but I like your suggestion about returning an enum. Will do a quick benchmark to confirm the switch does not affect too much.

srcRm.InstrumentationLibraryMetrics().RemoveIf(func(srcIm pdata.InstrumentationLibraryMetrics) bool {
// If we are done skip everything else.
if totalCopiedMetrics == size {
return false
Copy link
Member

Choose a reason for hiding this comment

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

The return true and return false operations for RemoveIf callbacks here are a bit difficult to understand (return false is not self-explanatory). Please add comments to explain what is happening.
A nicer approach perhaps would be to change RemoveIf's callback to return an enum instead of bool. In that case we could write e.g. return pdata.Remove, return pdata.Keep or return pdata.BreakIteration or similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, the "problem" is that we will avoid calling the callback but we still need to iterate over all to shift them to the left in case something was removed.

Benchmarks Before:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    6660	    170653 ns/op	  182889 B/op	    3309 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks After:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    7858	    134259 ns/op	  141881 B/op	    2596 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks Reference Clone:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkCloneMetrics
BenchmarkCloneMetrics-16    	    8726	    127948 ns/op	  137816 B/op	    2503 allocs/op
PASS

Process finished with the exit code 0
```

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
@bogdandrutu bogdandrutu merged commit deceea9 into open-telemetry:main May 5, 2021
@bogdandrutu bogdandrutu deleted the fixmetricsreorder branch May 5, 2021 20:55
dashpole pushed a commit to dashpole/opentelemetry-collector that referenced this pull request Jun 14, 2021
…try#3034)

Benchmarks Before:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    6660	    170653 ns/op	  182889 B/op	    3309 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks After:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    7858	    134259 ns/op	  141881 B/op	    2596 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks Reference Clone:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkCloneMetrics
BenchmarkCloneMetrics-16    	    8726	    127948 ns/op	  137816 B/op	    2503 allocs/op
PASS

Process finished with the exit code 0
```

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
ankitnayan pushed a commit to SigNoz/opentelemetry-collector that referenced this pull request Jul 27, 2021
…try#3034)

Benchmarks Before:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    6660	    170653 ns/op	  182889 B/op	    3309 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks After:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkSplitMetrics
BenchmarkSplitMetrics-16    	    7858	    134259 ns/op	  141881 B/op	    2596 allocs/op
PASS

Process finished with the exit code 0
```

Benchmarks Reference Clone:
```
goos: darwin
goarch: amd64
pkg: go.opentelemetry.io/collector/processor/batchprocessor
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkCloneMetrics
BenchmarkCloneMetrics-16    	    8726	    127948 ns/op	  137816 B/op	    2503 allocs/op
PASS

Process finished with the exit code 0
```

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
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.

3 participants