Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 9474c5c

Browse files
Fix block size for transfer
1 parent a713453 commit 9474c5c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

mars/oscar/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from .backends import allocate_strategy
4141
from .backends.pool import MainActorPoolType
42+
from .backends.transfer import temp_transfer_block_size
4243
from .batch import extensible
4344
from .core import (
4445
ActorRef,

mars/oscar/backends/transfer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@
4040
DEFAULT_TRANSFER_BLOCK_SIZE = 4 * 1024**2
4141

4242

43+
@contextlib.contextmanager
44+
def temp_transfer_block_size(size: int):
45+
global DEFAULT_TRANSFER_BLOCK_SIZE
46+
47+
if size == DEFAULT_TRANSFER_BLOCK_SIZE:
48+
yield
49+
else:
50+
default_size = DEFAULT_TRANSFER_BLOCK_SIZE
51+
DEFAULT_TRANSFER_BLOCK_SIZE = size
52+
try:
53+
yield
54+
finally:
55+
DEFAULT_TRANSFER_BLOCK_SIZE = default_size
56+
57+
4358
def _get_buffer_size(buf) -> int:
4459
try:
4560
return buf.nbytes

mars/services/storage/transfer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ async def send_batch_data(
207207
rest_keys.append(data_key)
208208

209209
if local_buffers:
210-
# for data that supports buffer protocol on both sides
211-
# hand over to oscar to transfer data
212-
await mo.copyto_via_buffers(local_buffers, remote_buffer_refs)
213-
await receiver_ref.close_writers(session_id, copied_keys)
210+
with mo.temp_transfer_block_size(block_size):
211+
# for data that supports buffer protocol on both sides
212+
# hand over to oscar to transfer data
213+
await mo.copyto_via_buffers(local_buffers, remote_buffer_refs)
214+
await receiver_ref.close_writers(session_id, copied_keys)
214215
else:
215216
rest_keys = to_send_keys
216217
rest_readers = readers

0 commit comments

Comments
 (0)