Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

WIP: Server streaming callable improvements - #403

Closed
igorbernstein2 wants to merge 31 commits into
googleapis:masterfrom
igorbernstein2:server-streaming-callable-improvements
Closed

WIP: Server streaming callable improvements#403
igorbernstein2 wants to merge 31 commits into
googleapis:masterfrom
igorbernstein2:server-streaming-callable-improvements

Conversation

@igorbernstein2

@igorbernstein2igorbernstein2 commented Oct 31, 2017

Copy link
Copy Markdown
Contributor

This is not ready for merging, its an early draft.

This is a rough draft of the ServerStreamingCallable api improvements that @garrettjonesgoogle & I were discussing. This PR is meant to get some early feedback on implementation direction and a sanity check. The code needs a lot of debugging, clean up, tests & doc but its feature complete.

Major changes:

  • add back pressure:
    • add ResponseObserver that replaces ApiStreamObserver for ServerStreamingCallables
    • add a StreamController that allows the user to manually adjust flow control
    • update the GrpcDirectServerStreamingCallable to use the new interfaces
  • move the conversion of async callbacks to iterator code out of grpc and into gax
    • add a ServerStream that replaces the old Iterator and duplicates the logic in grpc's ClientCalls
  • add syntatic sugar to convert a ServerStreamingCallable into UnaryCallables: first() & all()
  • deprecated all existing methods on ServerStreamingCallable

@garrettjonesgoogle, please take a look when you have a moment and let me know if I'm on the right track

@igorbernstein2
igorbernstein2force-pushed the server-streaming-callable-improvements branch from e8863d1 to 40a8843CompareNovember 1, 2017 22:17
@igorbernstein2

Copy link
Copy Markdown
ContributorAuthor

rebased

@codecov-io

codecov-io commented Nov 1, 2017

Copy link
Copy Markdown

Codecov Report

Merging #403 into master will increase coverage by 0.85%.
The diff coverage is 77.64%.

Impacted file tree graph

@@ Coverage Diff @@## master #403 +/- ##
============================================
+ Coverage 70.53% 71.38% +0.85% - Complexity 634 680 +46 
============================================
Files 136 143 +7 Lines 2912 3334 +422 Branches 220 265 +45 ============================================
+ Hits 2054 2380 +326 - Misses 776 846 +70 - Partials 82 108 +26
Impacted FilesCoverage ΔComplexity Δ
.../grpc/GrpcServerStreamingRequestParamCallable.java0% <0%> (ø)0 <0> (ø)⬇️
.../java/com/google/api/gax/rpc/StreamController.java100% <100%> (ø)2 <2> (?)
...om/google/api/gax/rpc/ServerStreamingCallable.java43.75% <42.3%> (-56.25%)5 <4> (+1)
...va/com/google/api/gax/core/SequentialExecutor.java70.21% <70.21%> (ø)4 <4> (?)
...m/google/api/gax/rpc/ReapingStreamingCallable.java75.47% <75.47%> (ø)6 <6> (?)
...main/java/com/google/api/gax/rpc/ServerStream.java78.18% <78.18%> (ø)6 <6> (?)
...in/java/com/google/api/gax/rpc/StreamMediator.java80.9% <80.9%> (ø)24 <24> (?)
.../java/com/google/api/gax/rpc/SpoolingCallable.java86.36% <86.36%> (ø)2 <2> (?)
...a/com/google/api/gax/rpc/FirstElementCallable.java87.5% <87.5%> (ø)2 <2> (?)
...pi/gax/grpc/GrpcDirectServerStreamingCallable.java95.74% <95%> (-4.26%)2 <0> (-1)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b86a50...710d036. Read the comment docs.

@garrettjonesgooglegarrettjonesgoogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't looked very deeply yet, but I would recommend merging from master sooner than later because I committed a large refactoring that will conflict with yours.

* disable automatic flow control. The receiver can also save a reference to the instance and
* terminate the stream early using {@code cancel()}.
*/
abstract class StreamController {

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle

Copy link
Copy Markdown
Contributor

Sorry I spoke too soon, you already rebased :-)

@igorbernstein2
igorbernstein2force-pushed the server-streaming-callable-improvements branch 2 times, most recently from 9ca1217 to 4c6b90fCompareNovember 2, 2017 23:39

@garrettjonesgooglegarrettjonesgoogle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall I like how this is turning out.

* Wraps a GRPC ClientCall in a {@link StreamController}. It feeds events to a {@link
* ResponseObserver} and allows for back pressure.
*/
static class GrpcStreamController<RequestT, ResponseT> extends StreamController {

This comment was marked as spam.

* control by calling {@code disableAutoInboundFlowControl()} in {@code onStart}. After which, the
* consumer must request responses by calling {@code request()}.
*/
public interface ResponseObserver<V> {

This comment was marked as spam.

*
* <p>By default, the stream uses automatic flow control, where the next response will be delivered
* as soon as the current one is processed by onResponse. A consumer can disable automatic flow
* control by calling {@code disableAutoInboundFlowControl()} in {@code onStart}. After which, the

This comment was marked as spam.

* <p>Can be called many times but is never called after {@link #onError(Throwable)} or {@link
* #onComplete()} are called.
*
* <p>Clients may may receive 0 or more onNext callbacks.

This comment was marked as spam.

@igorbernstein2

Copy link
Copy Markdown
ContributorAuthor

Ok, I'll apply those changes & break this up into smaller chunks to make it easier to review:

  • nonfunctional updates like pulling server streaming tests into their own files
  • adding ResponseObserver & back pressure
  • adding ServerStream
  • adding first() & all()
    It should ready for review on Monday morning

@igorbernstein2
igorbernstein2force-pushed the server-streaming-callable-improvements branch from ab56d25 to aa5dca1CompareNovember 16, 2017 22:19
@igorbernstein2
igorbernstein2 deleted the server-streaming-callable-improvements branch November 30, 2017 02:11
Sign up for freeto 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.

3 participants

@igorbernstein2@codecov-io@garrettjonesgoogle