Skip to content

Adding outbound flow control for Netty. - #348

Closed
nmittler wants to merge 2 commits into
grpc:masterfrom
nmittler:outflow
Closed

nmittler wants to merge 2 commits into
grpc:masterfrom
nmittler:outflow

Conversation

@nmittler

Copy link
Copy Markdown

No description provided.

@nmittler

Copy link
Copy Markdown
Author

@louiscryan @ejona86 can you take a look? I still have to add tests for outbound flow control, but I wanted to get thoughts on the implementation first.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be a much lower number, since the bandwidth-delay product between the application and the transport is the network's bandwidth * context switch latency.

Netty uses 32K for instance.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done.

@nmittler

Copy link
Copy Markdown
Author

@ejona86 PTAL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will end up notifying for each frame we sent after the queue is less than onReadyThreshold. We probably only want to notify if there has been another write (onSendingBytes())?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done.

@nmittler

Copy link
Copy Markdown
Author

@ejona86 PTAL

@nmittler

Copy link
Copy Markdown
Author

@ejona86 PTAL, I added synchronization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Need space before (

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done.

@nmittler

Copy link
Copy Markdown
Author

@ejona86 changes committed ... anything else at this point? If not, I'll start adding unit tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm... We can't actually call listener().onReady() here, as we are only supposed to call the listener from the transport thread. Nonetheless, it seems it may be safe from a threading perspective, but we would need to update documentation. There's also the possibility of recursive loops (application sends -> onReady() -> application sends -> onReady()) and application code may not be reentrant.

Would it be better to call onSendingBytes() within the event loop? However, it is nice to be able to know during writing that the application could continue sending, which would reduce latency.

Or maybe we should return a boolean for whether the buffer is full? We would only call onReady() if we returned that the buffer filled. If we had a method isReady(), that would be the Netty behavior, but I'm not sure it applies as well for us.

:-/ all around.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For efficiency of applications that obey outbound flow control, I think that immediately calling back during a write (and requiring the application code to be reentrant) is probably the best approach, so long as the documentation is clear. WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My feeling is that would lead to a lot of recursion, such that it could exhaust the stack. At 32K, we can fit 6.5K messages in the buffer.

If we are doing it for efficiency, then I think that returning a boolean would be a better approach. Doing a callback requires multiple allocations, has the reentrancy/recursion problem, has more synchronization in grpc, and needs more application synchronization between sender and listener. From a threading perspective, only doing callbacks from transport thread would also be a plus.

@nmittler

Copy link
Copy Markdown
Author

@ejona86 I've rebased my changes and changed the contract so that onReady is always called from the transport thread. I've also changed Stream.writeMessage to return a boolean to enable the immediate notification case.

/cc @louiscryan FYI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This won't work like you expect, since the framer will basically never have written out the frame at this point. Instead, I guess flush() should return the boolean.

@ejona86

ejona86 commented Apr 30, 2015

Copy link
Copy Markdown
Member

@nmittler, this approach looks like it will work.

Can we do the warning cleanup in a separate PR is important though? It is really making this PR noisy, which makes it much harder to review.

@nmittler

Copy link
Copy Markdown
Author

PTAL ... I've rebased the changes now that the warning fixes are in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should do the same thing here and for closed calls. Right now though one returns false and the other returns true.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ejona86 I'm not seeing what you mean? Which one returns false?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oh you mean ServerCall ... yeah, let me add this change there as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isReady() returns false if closed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wasn't meaning ServerCall, that was separate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Treat it the same as closed. If one returns true, then the other should return true. If false, false.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not getting what you're saying ... there is no closed flag that I can look at here. :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right now isReady() returns false if the stream is closed. Thus, I'm saying that this should be return false;. There is no need for a condition.

If return false; seems wrong, then isReady() should be changed to return true if the stream is closed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh ok ... the detail you were leaving out (and the source of my confusion) was that this is only used when an exception occurs in the start method ... meaning the call is closed. So in this case it makes sense to always return false.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

@ejona86

ejona86 commented Apr 30, 2015

Copy link
Copy Markdown
Member

Change ServerCall.sendPayload() as well?

@nmittler

Copy link
Copy Markdown
Author

@ejona86 committed updates for ServerCall ... would be nice if client/server shared a common interface hierarchy :)

@nicolasnoble

Copy link
Copy Markdown

Can one of the admins verify this patch?

@nmittler

nmittler commented May 1, 2015

Copy link
Copy Markdown
Author

@ejona86 PTAL ... if you're happy with this, I'll begin unit testing.

@ejona86

ejona86 commented May 1, 2015

Copy link
Copy Markdown
Member

@nmittler, yeah, things look good; I'm happy with it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants