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

Propagate explicit flushes through MessageFramer #323

Merged
merged 1 commit into from
Apr 21, 2015

Conversation

ejona86
Copy link
Member

@ejona86 ejona86 commented Apr 20, 2015

MessageFramer allows queing of data and explicit flushing. Sinks
generally can benefit from knowing when they are required to flush, so
we now tell them when MessageFramer received a flush so they only have
to flush when required.

This is an alternative to #313 which when combined with netty/netty#3670
would greatly decrease the number of TCP segments we send. The same
approach of this CL could be taken with headers to delay them if the request
is unary (which I think is already being done in OkHttp).

Note that this CL doesn't get all the gains we could. We currently do thread
synchronization in both OkHttp and Netty per-write. To optimize that we could
buffer in the sync until the flush arrives. This would allow combining header
writing into the same buffer. Alternatively, instead of the approach of this PR,
we could write batches of frames to the MessageFramer.Sink.

Note that all approaches discussed here aren't impacted by number of
messages being sent.

if (frame.readableBytes() > 0) {
sendFrame(frame, false);
sendFrame(frame, false, endOfStream ? false : flush);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why in the case of endOfStream do you not flush?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ... trailers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, trailers. We know on line 149 here that we will send trailers.

@nmittler
Copy link
Member

@ejona86 this looks very reasonable to me, should we just commit this? Or are you looking for discussion related to #313?

@ejona86
Copy link
Member Author

ejona86 commented Apr 21, 2015

Based on discussion with @louiscryan, I think there is room for both of these changes, since with #313 we likely will cap out the maximum buffer size we use in order to ensure we always use the buffer pool.

The main thing I am hesitant on is whether we want MessageFramer to do write a WritableBuffer[] instead of just a single WritableBuffer. For performance, I see both Netty and OkHttp wanting to buffer frames until they receive the flush (for less synchronization). It would make sense to do that in one place (MessageFramer), however both Netty and OkHttp may want to do that buffering for headers as well, and so buffering in MessageFramer wouldn't be enough.

@nmittler
Copy link
Member

Sounds good. LGTM as-is. The change to using WritableBuffer[] could be future work.

MessageFramer allows queing of data and explicit flushing. Sinks
generally can benefit from knowing when they are required to flush, so
we now tell them when MessageFramer received a flush so they only have
to flush when required.
@ejona86 ejona86 merged commit fc3e416 into grpc:master Apr 21, 2015
@ejona86 ejona86 deleted the flush-out-of-framer branch April 21, 2015 18:26
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants