-
Notifications
You must be signed in to change notification settings - Fork 719
Stop calling read(...) if we were not able to fill the whole buffer. #296
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
Conversation
|
This also gives a small perf improvement for HTTP benchmarks. |
Sources/NIO/SocketChannel.swift
Outdated
| result = .some | ||
|
|
||
| if buffer.writableBytes > 0 { | ||
| // If we not filled the whole buffer with read(...) we should stop reading and wait until we get notified again. |
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.
grammar nit: 'If we did not fill the whole buffer' ...
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.
fixed
weissi
left a comment
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.
looks good to me. Approved because you can ignore the grammar nit if you want ;)
88dc0f8 to
cbca34f
Compare
|
@weissi never! Fixed it 👍 |
Tests/NIOTests/ChannelTests.swift
Outdated
|
|
||
| func errorCaught(ctx: ChannelHandlerContext, error: Error) { | ||
| XCTAssertEqual(.read, self.state) | ||
| XCTAssertTrue(.read == self.state || .readComplete == self.state) |
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.
Why is this non-deterministic?
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.
actually I think .readComplete == is the only one we need to test... let me fix
Motivation: If we not filled the whole buffer with read(...) we should stop reading and wait until we get notified again. Otherwise chances are good that the next read(...) call will either read nothing or only a very small amount of data. Also this will allow us to call fireChannelReadComplete() which may give the user the chance to flush out all pending writes. Modifications: Stop reading and wait for next wakup when we not fill the whole buffer. Result: Less wasted read calls and early chance of flushing out pending data.
00c1317 to
f0f1a05
Compare
|
@Lukasa addressed |
Lukasa
left a comment
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 think this LGTM.
|
Rebase and merge when ready. |
Motivation:
If we not filled the whole buffer with read(...) we should stop reading and wait until we get notified again. Otherwise chances are good that the next read(...) call will either read nothing or only a very small amount of data.
Also this will allow us to call fireChannelReadComplete() which may give the user the chance to flush out all pending writes.
Modifications:
Stop reading and wait for next wakup when we not fill the whole buffer.
Result:
Less wasted read calls and early chance of flushing out pending data.