Faster sequential access for stored fields#62509
Merged
jimczi merged 4 commits intoelastic:masterfrom Sep 17, 2020
Merged
Conversation
Collaborator
|
Pinging @elastic/es-search (:Search/Search) |
b174460 to
7ce055b
Compare
jpountz
reviewed
Sep 17, 2020
Contributor
jpountz
left a comment
There was a problem hiding this comment.
Woohoo! The change makes sense to me overall although I'm not completely happy with cutting over entirely to CodecReader. I wonder if we should instead introduce a new subclass of LeafReader that introduces a new method such as getSequentialStoredFieldsReader and make sure all our security/exitable leaf readers implement it (I haven't fully thought through the implications).
server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java
Outdated
Show resolved
Hide resolved
Spinoff of elastic#61806 Today retrieving stored fields at search time is optimized for random access. So we make no effort to keep state in order to not decompress the same data multiple times because two documents might be in the same compressed block. This strategy is acceptable when retrieving a top N sorted by score since there is no guarantee that documents will be on the same block. However, we have some use cases where the document to retrieve might be completely sequential: * Scrolls or normal search sorted by document id. * Queries on Runtime fields that extract from _source. This commit allows to expose all the custom readers that we use at search time as codec readers in order to be able to leverage the merge instances of stored fields readers that are optimized for sequential access. This change focuses on the fetch phase for now and leverages the merge instances for stored fields only if all documents to retrieve are adjacent. Applying the same logic in the source lookup of runtime fields should be trivial but will be done in a follow up. The speedup on queries sorted by doc id is significant. I played with the scroll task of the [http_logs rally track](https://elasticsearch-benchmarks.elastic.co/#tracks/http-logs/nightly/default/30d) on my laptop and had the following result: ``` | Metric | Task | Baseline | Contender | Diff | Unit | |--------------------------------------------------------------:|-------:|------------:|------------:|---------:|--------:| | Total Young Gen GC | | 0.199 | 0.231 | 0.032 | s | | Total Old Gen GC | | 0 | 0 | 0 | s | | Store size | | 17.9704 | 17.9704 | 0 | GB | | Translog size | | 2.04891e-06 | 2.04891e-06 | 0 | GB | | Heap used for segments | | 0.820332 | 0.820332 | 0 | MB | | Heap used for doc values | | 0.113979 | 0.113979 | 0 | MB | | Heap used for terms | | 0.37973 | 0.37973 | 0 | MB | | Heap used for norms | | 0.03302 | 0.03302 | 0 | MB | | Heap used for points | | 0 | 0 | 0 | MB | | Heap used for stored fields | | 0.293602 | 0.293602 | 0 | MB | | Segment count | | 541 | 541 | 0 | | | Min Throughput | scroll | 12.7872 | 12.8747 | 0.08758 | pages/s | | Median Throughput | scroll | 12.9679 | 13.0556 | 0.08776 | pages/s | | Max Throughput | scroll | 13.4001 | 13.5705 | 0.17046 | pages/s | | 50th percentile latency | scroll | 524.966 | 251.396 | -273.57 | ms | | 90th percentile latency | scroll | 577.593 | 271.066 | -306.527 | ms | | 100th percentile latency | scroll | 664.73 | 272.734 | -391.997 | ms | | 50th percentile service time | scroll | 522.387 | 248.776 | -273.612 | ms | | 90th percentile service time | scroll | 573.118 | 267.79 | -305.328 | ms | | 100th percentile service time | scroll | 660.642 | 268.963 | -391.678 | ms | | error rate | scroll | 0 | 0 | 0 | % | ``` Closes elastic#62024
3377e71 to
6ed45fa
Compare
Contributor
Author
|
@jpountz , I modified this PR with your idea of having an abstract filter leaf reader that exposes |
jpountz
approved these changes
Sep 17, 2020
Contributor
jpountz
left a comment
There was a problem hiding this comment.
I like it, I find it simpler now.
...er/src/main/java/org/elasticsearch/common/lucene/index/SequentialStoredFieldsLeafReader.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java
Outdated
Show resolved
Hide resolved
...ava/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetReaderTests.java
Outdated
Show resolved
Hide resolved
jimczi
added a commit
that referenced
this pull request
Sep 17, 2020
Faster sequential access for stored fields Spinoff of #61806 Today retrieving stored fields at search time is optimized for random access. So we make no effort to keep state in order to not decompress the same data multiple times because two documents might be in the same compressed block. This strategy is acceptable when retrieving a top N sorted by score since there is no guarantee that documents will be on the same block. However, we have some use cases where the document to retrieve might be completely sequential: Scrolls or normal search sorted by document id. Queries on Runtime fields that extract from _source. This commit exposes a sequential stored fields reader in the custom leaf reader that we use at search time. That allows to leverage the merge instances of stored fields readers that are optimized for sequential access. This change focuses on the fetch phase for now and leverages the merge instances for stored fields only if all documents to retrieve are adjacent. Applying the same logic in the source lookup of runtime fields should be trivial but will be done in a follow up. The speedup on queries sorted by doc id is significant. I played with the scroll task of the http_logs rally track on my laptop and had the following result: | Metric | Task | Baseline | Contender | Diff | Unit | |--------------------------------------------------------------:|-------:|------------:|------------:|---------:|--------:| | Total Young Gen GC | | 0.199 | 0.231 | 0.032 | s | | Total Old Gen GC | | 0 | 0 | 0 | s | | Store size | | 17.9704 | 17.9704 | 0 | GB | | Translog size | | 2.04891e-06 | 2.04891e-06 | 0 | GB | | Heap used for segments | | 0.820332 | 0.820332 | 0 | MB | | Heap used for doc values | | 0.113979 | 0.113979 | 0 | MB | | Heap used for terms | | 0.37973 | 0.37973 | 0 | MB | | Heap used for norms | | 0.03302 | 0.03302 | 0 | MB | | Heap used for points | | 0 | 0 | 0 | MB | | Heap used for stored fields | | 0.293602 | 0.293602 | 0 | MB | | Segment count | | 541 | 541 | 0 | | | Min Throughput | scroll | 12.7872 | 12.8747 | 0.08758 | pages/s | | Median Throughput | scroll | 12.9679 | 13.0556 | 0.08776 | pages/s | | Max Throughput | scroll | 13.4001 | 13.5705 | 0.17046 | pages/s | | 50th percentile latency | scroll | 524.966 | 251.396 | -273.57 | ms | | 90th percentile latency | scroll | 577.593 | 271.066 | -306.527 | ms | | 100th percentile latency | scroll | 664.73 | 272.734 | -391.997 | ms | | 50th percentile service time | scroll | 522.387 | 248.776 | -273.612 | ms | | 90th percentile service time | scroll | 573.118 | 267.79 | -305.328 | ms | | 100th percentile service time | scroll | 660.642 | 268.963 | -391.678 | ms | | error rate | scroll | 0 | 0 | 0 | % | Closes #62024
This was referenced Sep 18, 2020
cbuescher
pushed a commit
that referenced
this pull request
Oct 6, 2020
In #62509 we already plugged faster sequential access for stored fields in the fetch phase. This PR now adds using the potentially better field reader also in SourceLookup. Rally exeriments are showing that this speeds up e.g. when runtime fields that are using "_source" are added e.g. via "docvalue_fields" or are used in queries or aggs. Closes #62621
cbuescher
pushed a commit
to cbuescher/elasticsearch
that referenced
this pull request
Oct 6, 2020
…tic#63035) In elastic#62509 we already plugged faster sequential access for stored fields in the fetch phase. This PR now adds using the potentially better field reader also in SourceLookup. Rally exeriments are showing that this speeds up e.g. when runtime fields that are using "_source" are added e.g. via "docvalue_fields" or are used in queries or aggs. Closes elastic#62621
cbuescher
pushed a commit
that referenced
this pull request
Oct 6, 2020
…) (#63316) In #62509 we already plugged faster sequential access for stored fields in the fetch phase. This PR now adds using the potentially better field reader also in SourceLookup. Rally exeriments are showing that this speeds up e.g. when runtime fields that are using "_source" are added e.g. via "docvalue_fields" or are used in queries or aggs. Closes #62621
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Faster sequential access for stored fields
Spinoff of #61806
Today retrieving stored fields at search time is optimized for random access.
So we make no effort to keep state in order to not decompress the same data
multiple times because two documents might be in the same compressed block.
This strategy is acceptable when retrieving a top N sorted by score since
there is no guarantee that documents will be on the same block.
However, we have some use cases where the document to retrieve might be
completely sequential:
This commit exposes a sequential stored fields reader in the
custom leaf reader that we use at search time.
That allows to leverage the merge instances of stored fields readers that
are optimized for sequential access.
This change focuses on the fetch phase for now and leverages the merge instances
for stored fields only if all documents to retrieve are adjacent.
Applying the same logic in the source lookup of runtime fields should
be trivial but will be done in a follow up.
The speedup on queries sorted by doc id is significant.
I played with the scroll task of the http_logs rally track
on my laptop and had the following result:
Closes #62024