Skip to content
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

Speed up ordinal lookups in composite aggregation #78313

Merged
merged 3 commits into from
Oct 6, 2021

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Sep 27, 2021

This change is an optimization on top of #74559, that sorts ordinals to perform
lookups. The sorting ensures that we don't do the de-compression of
blocks in the dictionary of terms more than necessary.
In the worst case today, we can decompress the same block for each lookup
term per segment, while this change requires only one decompression.

This commit also creates the doc values lookup once
per request per segment. This is useful when inverted lists
are used to shortcut the collection since terms are already sorted
in the dictionary.

This change is an optimization on top of #, that sorts ordinals to perform
lookups. The sorting ensures that we don't do the de-compression of
 blocks in the dictionary of terms more than necessary.
 In the worst case today, we can decompress the same block for each lookup
term per segment, while this change requires only one decompression.

This commit also creates the doc values lookup once
per request per segment. This is useful when inverted lists
 are used to shortcut the collection since terms are already sorted
 in the dictionary.
@jimczi jimczi requested a review from ywelsch September 27, 2021 11:21
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Sep 27, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into this. I've left two comments to address (and a bunch of optional ones)

assert leafReaderContextChanged == false || invariant(); // for performance reasons only check invariant upon change
return new LeafBucketCollector() {
@Override
public void collect(int doc, long bucket) throws IOException {
// caller of getLeafCollector ensures that collection happens before requesting a new leaf collector
// this is important as ordinals only make sense in the context of the current lookup
assert dvs == lookup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could still assert that they have same leaf reader context ordinal? i.e. that the ordinal-based operations here make sense.

@ywelsch ywelsch changed the title Speed up ordinal lookups in composte aggregation Speed up ordinal lookups in composite aggregation Sep 27, 2021
@not-napoleon
Copy link
Member

Have we run the ML performance test against this branch? This seems like it should help, but it'd be good to have the numbers to back that up.

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left two more minor comments, looking good o.w.

if (leafReaderContextChanged) {
remapOrdinals(lookup, dvs);
leafReaderOrd = context.ord;
// use a separate instance for ordinal and term lookups, that is cached per segment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't right for this method. Here, after your refactoring, we don't have a separate instance as there is no iteration anymore.

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we run the ML performance test against this branch? This seems like it should help, but it'd be good to have the numbers to back that up.

It would be great to have the results of this test before we merge this in, otherwise without an existing performance infrastructure, I feel like we are running blind with these changes.

@ywelsch
Copy link
Contributor

ywelsch commented Sep 30, 2021

Have we run the ML performance test against this branch? This seems like it should help, but it'd be good to have the numbers to back that up.

It would be great to have the results of this test before we merge this in, otherwise without an existing performance infrastructure, I feel like we are running blind with these changes.

Jim has done some ad-hoc testing.

Once this PR is merged (e.g. master-only in a first step), it can be validated by the ML QA team (@wwang500).

There's ongoing work to add benchmarking capabilities to Rally for paging through composite aggregations.

I would like this PR to go into 7.16 and not be blocked on benchmarking infrastructure.

stefnestor added a commit that referenced this pull request Oct 5, 2021
[7.14 update](http://github.com/elastic/elasticsearch/pull/74559) exacerbated performance concerns on composite aggregations & [fix in discussion](#78313) is either reverting or will come in 7.16. In the mean time users need disclaimer that before change this search was expensive & esp. now or w/upgrade may impact cluster performance.
@jimczi
Copy link
Contributor Author

jimczi commented Oct 6, 2021

I am going to merge in master only to allow ml to run their performance test. Depending on the results we'll decide if we can backport safely.

@jimczi jimczi merged commit f2580da into elastic:master Oct 6, 2021
@jimczi jimczi deleted the composite_sorted_ordinals branch October 6, 2021 16:19
jimczi added a commit that referenced this pull request Oct 12, 2021
The random tests in CompositeAggregatorTests create lots of segments since #78313. That can lead to out of memory in tests.
The additional commits were added to simulate the multi-segments case but the random index writer should already perform some random overcommits.

Closes #78919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v7.16.0 v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants