Skip to content
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

Send buffers in chunks <2GB #5134

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions distributed/comm/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async def read(self, deserializers=None):
2, range(0, frames_nbytes + C_INT_MAX, C_INT_MAX)
):
chunk = frames[i:j]
chunk_nbytes = len(chunk)
chunk_nbytes = chunk.nbytes
n = await stream.read_into(chunk)
assert n == chunk_nbytes, (n, chunk_nbytes)
except StreamClosedError as e:
Expand Down Expand Up @@ -268,16 +268,24 @@ async def write(self, msg, serializers=None, on_error="message"):
# trick to enque all frames for writing beforehand
for each_frame_nbytes, each_frame in zip(frames_nbytes, frames):
if each_frame_nbytes:
if stream._write_buffer is None:
raise StreamClosedError()
each_frame = memoryview(each_frame)

if isinstance(each_frame, memoryview):
# Make sure that `len(data) == data.nbytes`
# See <https://github.com/tornadoweb/tornado/pull/2996>
each_frame = memoryview(each_frame).cast("B")
# Make sure that `len(data) == data.nbytes`
# See <https://github.com/tornadoweb/tornado/pull/2996>
each_frame = each_frame.cast("B")

stream._write_buffer.append(each_frame)
stream._total_write_index += each_frame_nbytes
# Workaround for OpenSSL 1.0.2 (can drop with OpenSSL 1.1.1)
for i, j in sliding_window(
2, range(0, each_frame_nbytes + C_INT_MAX, C_INT_MAX)
):
chunk = each_frame[i:j]
chunk_nbytes = chunk.nbytes

if stream._write_buffer is None:
raise StreamClosedError()

stream._write_buffer.append(chunk)
stream._total_write_index += chunk_nbytes

# start writing frames
stream.write(b"")
Expand Down