-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 functions that allow to efficiently merge and downsample expo histograms #12328
base: main
Are you sure you want to change the base?
Conversation
This allows for a more efficient implementation for merging histograms
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 is a very custom solution for maybe not so common problem:
- I don’t see a benchmark, the pprof doesn’t tell me how much improvement is this.
- Have you tried the to implement the new Seq iterator available in 1.23 golang? We will be able to implement that in couple of weeks.
- What other alternatives have you considered?
Thanks for the quick feedback! I definitely acknowledge that these functions are rather specific to the use case for merging histograms. Having said that, merging histograms sounds like a common enough use case that pdata should allow for doing efficiently. I didn't know about the seq iterator in go 1.23. I'll have a look and see if that's a viable alternative. From a first glance, it didn't seem obvious how to implement something like Other solutions considered are converting exponential histograms into a custom data structure or go-expohisto that allow for a more efficient merging of histograms. But that requires another conversion step and allocations. This conversion could also benefit from a more efficient read access to the slice. Adding a range function should be generically applicable and less controversial. Another approach could be offering canonical implementation for merging histograms. It may use a similar method to the one proposed, but it wouldn't need changes in the primitive slices themselves. That would make sense if and when we see multiple processors re-implementing the same thing. With deltatocumulative and lsminterval there are at least two processors that are doing the same thing. |
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.
Could you restrict the generation of these methods only to the exponential histogram buckets structs?
It strikes me that this the n
in Collapse(n)
is more general than ought to be needed for exponential histogram users. The n
is always a power of two (or else it's being abused).
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 am strongly encourage that, before we have an agreement on this being a path to not waste too much resources in implementing this in the "right" way. We can have these funcs manually written initially (not generated) do the benchamarks etc. then we do a decision then we implement correctly.
Otherwise this will take a while and you will feel that we don't make "progress".
Thanks for the feedback and guidance. I’ll follow up next week when I’m back from an offsite. |
I found some time in between the sessions to implement two alternative implementations (455d680) and create a benchmark
My takeaway is that if we want an implementation that's as efficient as possible, we need direct access to the slice when modifying it, without going though abstraction layers. I can't think of another way to do it rather than adding functions to |
Yeah, true. But enforcing that n is a power of 2 doesn’t seem to make the function easier but even more specific to the downsampling use case. |
Somebody else implemented the Seq thing. See #12380 maybe you can add that as well (requires 1.23) |
Also, try the "brute" force to create a new slice and use FromRaw to install it, I know is an extra slice, but may use some sync.Pool on your side since we force a copy anyway. |
I'm not sure how you're envisioning the Seq iterator based implementation. I gave it a try by implementing a
|
I wonder if we should step back and ask whether there is some way to get access to the underlying slices, for example if the Pdata packages had mutator methods that check for the capability and return a pointer to the slice. This would introduce a certain potential for unsafe behavior for the potential gain that you're after. |
I would also try to understand if this is significant enough to justify the unsafe API. |
Updates from some of the discussions we had internally:
|
While testing the performance for merging exponential histograms in
lsmintervalprocessor
(which we're planning to contribute) that borrows the histogram merging logic from the deltatocumulative processor, we've found the process of merging histogram buckets to perform very poorly.The reason is that there's no low-level access to the underlying
UInt64Slice
, so read and especially write operations need to go through an abstraction that check whether the slice is in a mutable state.Instead of allowing direct access to the slice, which would not be safe, this PR proposes to add two methods to numeric slices that allow safe and efficient operations needed for merging and downsampling histograms.