-
Notifications
You must be signed in to change notification settings - Fork 2.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
Add a Downsampling writer that drop a percentage of spans #1353
Add a Downsampling writer that drop a percentage of spans #1353
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.
@yurishkuro I tried running some benchmark against sync.Pool, something like the following two.
Against another version where I just use mutex for locking, it seems the simple mutex beats sync.Pool in both scenarios. I think using sync.Pool here is not necessary since we don't need to do fnv.New64a()
everytime hashing: Just need to do fnv.reset()
to reset it which doesn't involve memory allocation thus sync.Pool won't help here?(But I might be wrong) So i prefer we just use mutex here.
Ran a benchmark against both mutex and sync.Pool versions that spawns 50000 goroutines where each goroutine WriteSpan 10000 times
(writeSpan is mutex version and writeSpan2 is sync.Pool version)
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.
mutex looks good.
You should use reset() even with the pool. The point of the pool is to avoid memory allocations. But in any case, we have an issue with the overall design where we run many go-routines working independently on saving spans, but we have these synchronization points like your mutex that block all writers for little reason. Unfortunately, fixing this requires significant re-design where we create writers per goroutine. Given that both the explicit mutex and sync.Pool introduce a critical section, the main benefit of the pool should be in avoiding memory allocations while unblocking other goroutines invoking the hash. If you're not getting the benefits of the sync pool with your benchmark, I suspect the benchmark. |
@guanw can you add your benchmarks so we can see? In your benchmark you maybe creating threads but not actually waiting for them to run before the benchmark resolves. @yurishkuro |
If it's some crap about how one day aliens will invade and the underlying implementation will in the future require you to call reset before every call so we should prepare for it now... |
as alternative to allocating a new buffer |
The underlying implementation of the hash is:
where
The underlying hash function doesn't use a buffer for representation. All reset does is:
|
I tried moving the fnv hash logic directly to our code and get rid of the sync.pool. It reduces the benchmark runtime 5x, I think we could just go with that? |
actually ignore my last comment. I'm still going with sync.Pool. |
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.
do we have 100 code coverage?
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.
nearly there
return math.MaxUint64 | ||
} | ||
return h.Sum64() | ||
//Currently fnv.Write() doesn't throw any error so metrics is not necessary here. |
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: space between //
and Currently
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.
also, linter might complain that we are swallowing the error.
} | ||
|
||
var instance *poolSingleton | ||
var once sync.Once |
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.
Pools should be fields of the factory, not globals. Pointers are not needed.
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.
Not sure I got the first part. Here instance is lowercase so it won't be exposed to other files. In factory.go the default is to disable DownsamplingWriter entirely so doesn't make sense to create pool there if we are not using downsamplingWriter as default?
I will get rid of the pointer though.
return ds.spanWriter.WriteSpan(span) | ||
} | ||
|
||
//hashBytes returns the uint64 hash value of bytes slice. |
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.
ping
@yurishkuro @black-adder @vprithvi Any more comments on this one? |
@yurishkuro any more comments on this? |
@yurishkuro updated. |
@yurishkuro Please let me know if you have any more comments. |
…h predefined config Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
…code coverage Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Signed-off-by: Jude Wang <[email protected]>
Accidentally removed my forked jaeger project so have to create this new pull request..
Which problem is this PR solving?
Short description of the changes
Ratio parameter is specified by passing
DOWN_SAMPLING_RATIO
as env variable.