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
postings: use Loser Tree for merge #12878
Conversation
d40d6d5
to
4654c42
Compare
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.
Impressive, can't wait for the talk to be online.
Hey Bryan, is this ready to merge? There are a few conflicts ;) We looked at this in our bug scrub. |
Yes it can be merged. I had hoped to get the implementation closer between Loki and Prometheus, but currently there is too much of a performance loss to do that. Also you might not want to take a dependency on something from my personal account. There are precedents - alecthomas, cespare, dennwc, klauspost. |
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
It's faster. Note change to test - instead of requiring that the data structure is identical to `EmptyPostings()`, check that calling `Next()` returns false, which implies it was empty. Also the check for context cancellation during initialization was removed. Initialization should be a small portion of the work done during merge, so it's not worth plumbing a context argument through. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
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.
LGTM! Thanks 💪🏽
Is this change ready to merge? Looking forward to test it |
Hi @bboreham, may I know if you have any benchmark for mergedPostings |
I don't recall benchmarking Some of the queries in |
For information, Bryan's talk is now available at https://www.youtube.com/watch?v=AmLtlXEo4UU |
Loser Tree is an alternative to Heap for k-way merge. It's faster because it doesn't call
Less()
andSwap()
through dynamic dispatch, and because it stores the value at the front of each sequence so saves callingAt()
over and over.Full disclosure: I'm doing a talk about this algorithm at GopherCon next week.
I added a benchmark because none of the existing ones merge enough series to show the difference.
Loser tree does use more memory, but not a lot in the context of PromQL evaluation.
Note change to test - instead of requiring that the data structure is identical to
EmptyPostings()
, check that callingNext()
returns false, which implies it was empty.