-
-
Notifications
You must be signed in to change notification settings - Fork 715
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
Rework BatchedSend logic #661
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d8897a2
Rework BatchedSend logic
pitrou 1f931c0
Address review comments
pitrou e746b32
Remove BatchedStream
pitrou 6b6c492
Remove fragile wait on IOStream.write()
pitrou 1a2e190
Merge branch 'master' of https://github.com/dask/distributed into bat…
pitrou ac1fbb1
Flush streams before closing to avoid losing messages.
pitrou 05b7c92
Yield on the flush() call
pitrou eb6afe8
Avoid exposing close()
pitrou b0e92f0
Fix name clash with close()
pitrou a22650d
Add a large traffic jam test
pitrou 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
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 |
---|---|---|
|
@@ -186,7 +186,7 @@ def handle_stream(self, stream, address): | |
break | ||
finally: | ||
try: | ||
stream.close() | ||
yield close(stream) | ||
except Exception as e: | ||
logger.warn("Failed while closing writer", exc_info=True) | ||
logger.info("Close connection from %s:%d to %s", address[0], address[1], | ||
|
@@ -229,11 +229,36 @@ def write(stream, msg): | |
stream.write(b''.join(lengths)) | ||
|
||
for frame in frames: | ||
# Can't wait for the write() Future as it may be lost | ||
# ("If write is called again before that Future has resolved, | ||
# the previous future will be orphaned and will never resolve") | ||
stream.write(frame) | ||
|
||
yield gen.moment | ||
|
||
|
||
@gen.coroutine | ||
def flush(stream): | ||
"""Flush the stream's output buffer. | ||
This is recommended before closing the stream. | ||
""" | ||
if stream.writing(): | ||
yield stream.write(b'') | ||
|
||
|
||
@gen.coroutine | ||
def close(stream): | ||
"""Close a stream safely. | ||
""" | ||
if not stream.closed(): | ||
try: | ||
flush(stream) | ||
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 we yield on this? 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. Yes, you're right, my bad. |
||
except StreamClosedError: | ||
pass | ||
finally: | ||
stream.close() | ||
|
||
|
||
def pingpong(stream): | ||
return b'pong' | ||
|
||
|
@@ -295,7 +320,7 @@ def send_recv(stream=None, arg=None, ip=None, port=None, addr=None, reply=True, | |
else: | ||
response = None | ||
if kwargs.get('close'): | ||
stream.close() | ||
close(stream) | ||
raise gen.Return(response) | ||
|
||
|
||
|
@@ -398,7 +423,7 @@ def close_streams(self): | |
for stream in self.streams: | ||
if stream and not stream.closed(): | ||
try: | ||
stream.close() | ||
close(stream) | ||
except (OSError, IOError, StreamClosedError): | ||
pass | ||
self.streams.clear() | ||
|
@@ -551,15 +576,15 @@ def collect(self): | |
self.open, self.active) | ||
for streams in list(self.available.values()): | ||
for stream in streams: | ||
stream.close() | ||
close(stream) | ||
|
||
def close(self): | ||
for streams in list(self.available.values()): | ||
for stream in streams: | ||
stream.close() | ||
close(stream) | ||
for streams in list(self.occupied.values()): | ||
for stream in streams: | ||
stream.close() | ||
close(stream) | ||
|
||
|
||
def coerce_to_address(o, out=str): | ||
|
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
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.
How do we know that this will complete?
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.
The API expects that
write()
isn't called beforeflush()
completes.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.
Are we confident that this expectation is fulfilled?
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.
I've updated the docstring to better inform the reader. But perhaps we only want to expose close() so that we don't do any further mistakes. What do you think?
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.
I'm mostly concerned about us as users. Only very advanced dask/distributed users should use read/write/close directly.
However, given that we've had problems reported it's possible that we aren't handling everything well internally.
I have no problem with read/write/close as an API generally.