-
Notifications
You must be signed in to change notification settings - Fork 1.2k
trace: use weak in TracerProvider for storing tracers #6655
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
base: main
Are you sure you want to change the base?
Conversation
HI @pellared, I used Am I using the wrong approach here? |
The linked issue in the description seems unrelated to this PR. Note that we won't be able to merge this until 1.25 is released (which is when we will drop support for 1.23). |
Sorry, my bad, updated.
I know it, this pr is submitted as a PoC for early review. as @pellared say
|
sdk/trace/provider.go
Outdated
@@ -67,7 +69,7 @@ type TracerProvider struct { | |||
embedded.TracerProvider | |||
|
|||
mu sync.Mutex | |||
namedTracer map[instrumentation.Scope]*tracer | |||
namedTracer sync.Map |
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.
namedTracer sync.Map | |
namedTracer sync.Map // map[instrumentation.Scope]weak.Pointer[*tracer] |
Annotate the expected type.
sdk/trace/provider.go
Outdated
provider: p, | ||
instrumentationScope: is, | ||
var tracerPtr *tracer | ||
for { |
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 this is coming from https://go.dev/blog/cleanups-and-weak. But using an infinite loop with an unclear break is a code smell.
stp.Tracer(names[i]) | ||
} | ||
b.StopTimer() | ||
b.Run("NoWeak, NoCleanup", func(b *testing.B) { |
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'm not sure if this test method is correct or reasonable.
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.
If this tests are reasonable, weak+cleanup
works better based on the results.
BenchmarkTracerCleanup/WithWeakAndCleanup-8 691965 1630 ns/op 592 B/op 13 allocs/op
BenchmarkTracerCleanup/NoWeak,_NoCleanup
BenchmarkTracerCleanup/NoWeak,_NoCleanup-8 304090 91877 ns/op 253 B/op 5 allocs/op
Hi, currently I have no time to review this PR, but I just want to call out that use of |
Yes, this is right, The initial Benchmark test show
the second test, forcing I think this improvement comes from weak+cleanup lowering GC pressure. finally, thank you for the insightful reply. |
#6351
unique name
same name: