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
Avoid flushing the stream after writing a message in case the server returns a single response #9273
Conversation
…the server returns a single response
|
Have you confirmed whether this makes a difference with a packet dump? Digging into the code, it seems this could improve things, but only because we already have this optimization later on in the write path: grpc-java/core/src/main/java/io/grpc/internal/AbstractServerStream.java Lines 109 to 111 in 428b541
|
Yeah, I think this just may work. This was what I thought was the hard part! But the plumbing in the transport already has a solution! Delaying the flush for the initial response should be relatively easy and similar to client-side. We just need to use grpc-java/netty/src/main/java/io/grpc/netty/NettyServerStream.java Lines 99 to 103 in 428b541
(That's fine as a separate PR) |
It seems to create the same number of packets. Maybe if the message body + trailers were aggregated into a single netty object before flushing it would make it a single packet? I don't have enough Netty know how to tell. |
Would that require the |
Yes, it would.
I thought we'd just do it in io.grpc.netty, not in the ServerCall. But I see now, NettyServerStream doesn't have access to the MethodDescriptor like NettyClientStream does. That's because it is determined later, after the call starts. We could either pass the method descriptor down into the server stream using a new method, or plumb the decision down in writeHeaders(). It makes sense to me to pass the flush decision as an argument to writeHeaders(). (That'd differ from client-side, but really, we could do the same thing on client-side and it wouldn't be bad.) |
Resolves #4884