-
Notifications
You must be signed in to change notification settings - Fork 186
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
Rr/sc 60366 sparse global order reader merge #5417
Open
rroelke
wants to merge
214
commits into
main
Choose a base branch
from
rr/sc-60366-sparse-global-order-reader-merge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+9,303
−785
Conversation
This file contains 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
…e C++ API in some parts for better exception handling
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.
The story contains more details, but in brief this pull request adds an additional mode to the sparse global order reader in which we pre-process the minimum bounding rectangles of all tiles from all fragments to determine a single global order in which all of the tiles must be loaded.
This pre-processing step is implemented using a "parallel merge" algorithm which merges the tiles from each fragment (which are arranged in global order within the fragment).
Parallel Merge
The parallel merge code lives in
tiledb/common/algorithm/parallel_merge.h
. It is written generically to merge streams of a copyable typeT
using any type which can compareT
(default isstd::less<T>
of course). An explanation of the algorithm is provided within the file.The top-level function
parallel_merge
is asynchronous, i.e. it returns a future which can be polled to see how much of the merge has already completed. This enables callers to begin processing merged data from the head of the eventual output before the tail of the eventual output has finished.Sparse Global Order Reader
We extend the sparse global order reader with a new configuration
sm.query.sparse_global_order.preprocess_tile_merge
. If nonzero, the sparse global order reader will run a parallel merge on the fragments to find the unified tile order and then use that to populate result tiles.preprocess_compute_result_tile_order
kicks off the parallel merge.create_result_tiles_using_preprocess
advances along the global tile order to create result tiles.The fields which are used for the old "per fragment result tiles" mode have been encapsulated into their own struct to emphasize that their use does not overlap with this new mode.
create_result_tiles_using_preprocess
does not need a per-fragment memory budget; instead it pulls tiles off of the globally ordered tile list until it has saturated the memory budget as much as it can.Tiles in the unified global order are arranged on their lower bound. The upper bounds of the tiles in the list may be out of order. To prevent cells from tile A to be emitted out of order with cells from tile B, we augment
add_next_cell_to_queue
to check the lower bound of the tiles which have not populated result tiles yet.The value of
sm.query.sparse_global_order.preprocess_tile_merge
configures the minimum amount of work that each parallel unit of the merge will do. This is so we can benchmark with different values without re-compiling; we will either want to recommend a value to customers, or choose one and flip this to a boolean.Serialization
The unified global tile order is state which must be communicated back and forth between the client and REST server. We can either serialize this whole list (16 bytes per tile across all fragments) or we can re-compute the parallel merge each time we run a
submit
on the REST server side.The current implementation chooses the latter, assuming that smaller messages are preferred to the additional CPU overhead.It turns out that we must serialize the tile order. The parallel merge algorithm should be deterministic, but it turns out that some aspect of the REST server state sometimes causes the subarray qualifying tile ranges to vary from one iteration to the next, which means that we cannot recompute the tile order in the same way.Testing
Testing of all changes is augmented using rapidcheck. With this library, rather than writing some test data examples, we write properties which contain generic claims about what the expected output must look like for a given input. The
rapidcheck
runtime generates arbitrary inputs to the property to test our claims.The parallel merge algorithm is tested in
unit_parallel_merge.cc
and has rapidcheck properties implemented for each step of the algorithm.The sparse global order reader tests are in
unit-sparse-global-order-reader.cc
. The gist is that we have a generic functionCSparseGlobalOrderFx::run
which writes a bunch of fragments, and then reads the data back in global order, comparing against an expected result. There's a fair bit of refactoring to support this. For 1D arrays we have testsSparse global order reader: fragment skew
,fragment interleave
, andfragment many overlap
which set up inputs which are expected to exercise some of the edge cases in the global order reader. And then we addrapidcheck 1D
andrapidcheck 2D
tests which generate totally arbitrary 1D and 2D inputs respectively.Performance Results
I still have more to do here, but things are looking pretty good... will fill in more details here as I have them. Notes are here.
TYPE: FEATURE | BUG | IMPROVEMENT
DESC: sparse global order reader determine global order of result tiles