-
Notifications
You must be signed in to change notification settings - Fork 3
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
Always stream out blocks in dods_encode
#10
Open
dcherian
wants to merge
2
commits into
xpublish-community:master
Choose a base branch
from
dcherian:maybe-better-dask
base: master
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.
+32
−14
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,6 +42,7 @@ | |||||
|
||||||
import re | ||||||
from dataclasses import dataclass | ||||||
from dask.cache import Cache | ||||||
|
||||||
import dask.array as da | ||||||
import numpy as np | ||||||
|
@@ -53,6 +54,13 @@ | |||||
@dataclass | ||||||
class Config: | ||||||
DASK_ENCODE_CHUNK_SIZE: int = 20e6 | ||||||
DASK_CACHE_SIZE: int = 120 * 1024 * 1024 # 120MB | ||||||
|
||||||
# we load one `DASK_ENCODE_CHUNK_SIZE`-sized block of linearized data | ||||||
# in to memory at one go. This may overlap with multiple dask chunks | ||||||
# so lets cache those chunks since we might come back to them. | ||||||
cache = Cache(Config.DASK_CACHE_SIZE) | ||||||
cache.register() | ||||||
|
||||||
|
||||||
class DAPError(Exception): | ||||||
|
@@ -491,8 +499,9 @@ def dods_encode(data, dtype): | |||||
if isinstance(data, da.Array): | ||||||
# Encode in chunks of a defined size if we work with dask.Array | ||||||
chunk_size = int(Config.DASK_ENCODE_CHUNK_SIZE / data.dtype.itemsize) | ||||||
serialize_data = data.ravel().rechunk(chunk_size) | ||||||
for block in serialize_data.blocks: | ||||||
flat = data.ravel() | ||||||
for start in range(0, data.size, chunk_size): | ||||||
block = flat[slice(start, chunk_size)] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clearly this needs tests! |
||||||
yield block.astype(dtype.str).compute().tobytes() | ||||||
else: | ||||||
# Make sure we always encode an array or we will get wrong results | ||||||
|
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.
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.
Shouldn't this be configured at the server level? That is what we do
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.
Now I think we should apply the cache more locally in that loop in
dods_encode
. We want to cache aggressively when we have multiple batches to stream out for a single request from a single array. This is because the order in which weyield
bytes can be orthogonal to chunking, and we can visit the same chunk multiple times.I think the more global server cache is appropriate for a less aggressive cache across multiple requests.
Perhaps we can pair at some point and just iterate through some options with a benchmark problem.
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.
Also seems like a good place to stick in a bit of async: compute the next iteration while streaming out the current iteration.