-
Notifications
You must be signed in to change notification settings - Fork 288
Lock RemotelyControlledSampler.sampler on callbacks #543
Conversation
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.
Thank you for this contribution and noticing this issue. However, I think this PR can be simplified by using the already existing locking in RemotelyControlledSampler
in the OnCreateSpan
method:
https://github.com/jaegertracing/jaeger-client-go/blob/master/sampler_remote.go#L98
This method is ultimately what calls IsSampled
on the nested sampler.
The lock is already being used here:
https://github.com/jaegertracing/jaeger-client-go/blob/master/sampler_remote.go#L183
to protect the Update
method which you noticed races with IsSampled
.
Also, if you could add data race testing similar to the testing for the span it would help confirm the fix worked:
https://github.com/jaegertracing/jaeger-client-go/blob/master/span_test.go#L365
We have another locking related PR #528 |
Signed-off-by: Dima Kozlov <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
==========================================
+ Coverage 88.19% 88.52% +0.33%
==========================================
Files 61 61
Lines 3277 3285 +8
==========================================
+ Hits 2890 2908 +18
+ Misses 260 251 -9
+ Partials 127 126 -1
Continue to review full report at Codecov.
|
Thanks for viewing PR! I've changed code with use of RemotelyControlledSampler.Lock() |
Added TestRemotelyControlledSampler_updateRace also |
Signed-off-by: Dima Kozlov <[email protected]>
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.
Thanks for the contribution! Looks good to me. Benchmarks below:
master
/jaeger-client-go (master)$ ./benchmark.bin -test.bench=BenchmarkTracer -test.run=BenchmarkTracer
goos: linux
goarch: amd64
pkg: github.com/uber/jaeger-client-go
BenchmarkTracer/sampler=NeverSample/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 6488808 188 ns/op
BenchmarkTracer/sampler=NeverSample/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 5012667 274 ns/op
BenchmarkTracer/sampler=AlwaysSample/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 3443355 379 ns/op
BenchmarkTracer/sampler=AlwaysSample/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 3072049 386 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleNoLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 1713846 644 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleNoLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 4692938 299 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleNoLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 702218 1450 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleNoLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 2399791 710 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleWithLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 735396 1431 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleWithLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 989468 1269 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleWithLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 952508 1267 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleWithLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 897516 1413 ns/op
PASS
hummerd:master
/jaeger-client-go (hummerd-master)$ ./benchmark.bin -test.bench=BenchmarkTracer -test.run=BenchmarkTracer
goos: linux
goarch: amd64
pkg: github.com/uber/jaeger-client-go
BenchmarkTracer/sampler=NeverSample/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 6395553 201 ns/op
BenchmarkTracer/sampler=NeverSample/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 4526431 253 ns/op
BenchmarkTracer/sampler=AlwaysSample/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 3410322 347 ns/op
BenchmarkTracer/sampler=AlwaysSample/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 2723958 569 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleNoLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 1444323 842 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleNoLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 3284641 437 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleNoLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 769690 1517 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleNoLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 2167453 644 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleWithLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 781092 1469 ns/op
BenchmarkTracer/sampler=AdaptiveNeverSampleWithLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 749485 1554 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleWithLateBinding/remoteSampler=false/children=false/tags=5/ops=10/cpus-8 1189791 1192 ns/op
BenchmarkTracer/sampler=AdaptiveAlwaysSampleWithLateBinding/remoteSampler=false/children=true/tags=5/ops=10/cpus-8 855861 1382 ns/op
PASS
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.
Thanks!
We've detected some race condition. In case you are using
RemotelyControlledSampler
it will call to Update method for sampler in it's background settings-polling routine. In the same time IsSampled (or any other exposed method of sampler) can be called from another goroutine and try to access sampler's data.Signed-off-by: Dima Kozlov [email protected]