-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
1f19db8
to
18bf0e7
Compare
|
||
// If possible to move all metrics do that. | ||
srcMetricsLen := srcIm.Metrics().Len() | ||
if size-totalCopiedMetrics >= srcMetricsLen { |
There was a problem hiding this comment.
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:
if size-totalCopiedMetrics >= srcMetricsLen { | |
remainingSpace := size - totalCopiedMetrics | |
if srcMetricsLen <= remainingSpace { | |
totalCopiedMetrics += srcMetricsLen |
srcIm.Metrics().RemoveIf(func(srcMetric pdata.Metric) bool { | ||
// If we are done skip everything else. | ||
if totalCopiedMetrics == size { | ||
return false |
There was a problem hiding this comment.
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 :-) )
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
18bf0e7
to
df1710d
Compare
…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>
…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>
Benchmarks Before:
Benchmarks After:
Benchmarks Reference Clone:
Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com