forked from dask/distributed
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow P2P to store data in-memory (dask#8279)
- Loading branch information
1 parent
ce813eb
commit cbc3a33
Showing
12 changed files
with
228 additions
and
24 deletions.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from collections import defaultdict, deque | ||
from typing import Any, Callable | ||
|
||
from dask.sizeof import sizeof | ||
|
||
from distributed.shuffle._buffer import ShardsBuffer | ||
from distributed.shuffle._limiter import ResourceLimiter | ||
from distributed.utils import log_errors | ||
|
||
|
||
class MemoryShardsBuffer(ShardsBuffer): | ||
_deserialize: Callable[[bytes], Any] | ||
_shards: defaultdict[str, deque[bytes]] | ||
|
||
def __init__(self, deserialize: Callable[[bytes], Any]) -> None: | ||
super().__init__( | ||
memory_limiter=ResourceLimiter(None), | ||
) | ||
self._deserialize = deserialize | ||
self._shards = defaultdict(deque) | ||
|
||
async def _process(self, id: str, shards: list[bytes]) -> None: | ||
# TODO: This can be greatly simplified, there's no need for | ||
# background threads at all. | ||
with log_errors(): | ||
with self.time("write"): | ||
self._shards[id].extend(shards) | ||
|
||
def read(self, id: str) -> Any: | ||
self.raise_on_exception() | ||
if not self._inputs_done: | ||
raise RuntimeError("Tried to read from file before done.") | ||
|
||
with self.time("read"): | ||
data = [] | ||
size = 0 | ||
shards = self._shards[id] | ||
while shards: | ||
shard = shards.pop() | ||
data.append(self._deserialize(shard)) | ||
size += sizeof(shards) | ||
|
||
if data: | ||
self.bytes_read += size | ||
return data | ||
else: | ||
raise KeyError(id) |
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
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
Oops, something went wrong.