This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
feat: optimize unary callables to not wait for trailers #1356
Merged
igorbernstein2
merged 13 commits into
googleapis:master
from
igorbernstein2:optimize-trailers
Jul 19, 2021
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2bf1e65
feat: optimize unary callables to not wait for trailers [draft]
igorbernstein2 f249f2b
add an opt-in for skipping trailers
igorbernstein2 3a70584
Merge branch 'master' into optimize-trailers
igorbernstein2 fc39fe9
oops
igorbernstein2 e244ec0
address feedback
igorbernstein2 c1ab13d
remove separate callable
igorbernstein2 6d838a0
oops
igorbernstein2 b070b4e
Merge branch 'master' into optimize-trailers
igorbernstein2 2b2d3ea
format
igorbernstein2 340a624
Merge branch 'master' into optimize-trailers
igorbernstein2 678d28e
Merge branch 'master' into optimize-trailers
igorbernstein2 eeef6b7
Merge remote-tracking branch 'origin/master' into optimize-trailers
igorbernstein2 173fb01
Merge remote-tracking branch 'igor/optimize-trailers' into optimize-t…
igorbernstein2 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.UnaryCallable; | ||
import com.google.common.base.Preconditions; | ||
import io.grpc.ClientCall; | ||
import io.grpc.MethodDescriptor; | ||
import io.grpc.stub.ClientCalls; | ||
|
||
|
@@ -44,18 +45,25 @@ | |
*/ | ||
class GrpcDirectCallable<RequestT, ResponseT> extends UnaryCallable<RequestT, ResponseT> { | ||
private final MethodDescriptor<RequestT, ResponseT> descriptor; | ||
private final boolean awaitTrailers; | ||
|
||
GrpcDirectCallable(MethodDescriptor<RequestT, ResponseT> descriptor) { | ||
GrpcDirectCallable(MethodDescriptor<RequestT, ResponseT> descriptor, boolean awaitTrailers) { | ||
this.descriptor = Preconditions.checkNotNull(descriptor); | ||
this.awaitTrailers = awaitTrailers; | ||
} | ||
|
||
@Override | ||
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) { | ||
Preconditions.checkNotNull(request); | ||
Preconditions.checkNotNull(inputContext); | ||
|
||
return new ListenableFutureToApiFuture<>( | ||
ClientCalls.futureUnaryCall(GrpcClientCalls.newCall(descriptor, inputContext), request)); | ||
ClientCall<RequestT, ResponseT> clientCall = GrpcClientCalls.newCall(descriptor, inputContext); | ||
|
||
if (awaitTrailers) { | ||
return new ListenableFutureToApiFuture<>(ClientCalls.futureUnaryCall(clientCall, request)); | ||
} else { | ||
return GrpcClientCalls.eagerFutureUnaryCall(clientCall, request); | ||
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. So this is is not wrapped with 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. GrpcClientCalls is owned by gax, so it already returns an ApiFuture, whereas ClientCalls is owned by grpc returns a ListenableFuture |
||
} | ||
} | ||
|
||
@Override | ||
|
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.
Should client libraries really consider the cases of the server side being misconfigured? Keeping server-side correct should be the responsibility of the server-side implementation and should not propagate to client side.
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 wanted to minimize the behavioral differences and its fairly cheap. If you feel strongly, I can remove it. let me know
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.
Behavioral differences between what and what? I would still recommend removing it though.
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.
Difference between grpc behavior and this. It will also ensure that the call is properly closed as opposed to hanging indefinitely if a second message is sent. Overall I think it makes debugging easier