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

Experimental download-style streaming responses #110

Merged
merged 7 commits into from
Jun 22, 2018

Conversation

mikeylemmon
Copy link

Issue #, if available: #70, #3

Description of changes:

This PR fleshes out some of the ideas discussed in the streaming-related issues, adding support for download-style streamed responses to the go generator, as well as a streaming MakeHats rpc to the example and a test_example target to the root Makefile.

Some things to note:

  • This PR only implements protobuf streams. There are failing tests for json that are commented out in the file example/cmd/server/main_test.go. Other than the example server tests, these additions don't have test coverage yet.
  • The response writer is flushed after each message. Some form of batching would dramatically improve throughput in high-load scenarios — by 10x or more based on initial experiments
  • Whitespace varies between spaces and tabs in generator.go. In areas of the file where I was already making changes, I consolidated to tabs, resulting in a couple spots in the diff that are just whitespace changes.

I'll be posting deeper thoughts/feelings in #70 as that is where the bulk of discussion has been taking place. Looking forward to feedback!

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* Use "EncodeMessage" instead of "Marshal" in serve<methName>Protobuf so message length is written properly
* Flush stream response after each message if response writer implements http.Flusher
* Add streaming "MakeHats" endpoint to example service
* Also, add tests for example server
* JSON clients currently fail to stream (rpc call gets EOF err instead of RespStream)
* Add new "test_example" target to Makefile. Example tests are passing for protobuf clients; JSON tests would fail, but are commented out
* Return normal twirp errors from download requests that fail before the stream is created
* Consolidate generator logic for unary and download rpc types in generateServerProtobufMethod
* In the example server, use chan of HatOrError type to send mid-stream errors
@spenczar spenczar self-requested a review May 31, 2018 19:31
* Define `<Type>OrError` struct that is a union of the `<Type>` and `error` return values from `Next`
* Define `New<Type>Stream` constructor that takes a channel of `<Type>OrError` and returns an implementation of the `<Type>Stream` interface
@mikeylemmon
Copy link
Author

@spenczar latest commit updates to the new <-chan RespOrError API for download-style rpcs -- it definitely feels cleaner to use!

The generated server code is still flushing on every message, probably a couple weeks before I'd be able to get into attempting a FlushStrategy implementation.

@spenczar
Copy link
Contributor

I've been discussing this branch with @fritzherald over slack. I'm going to merge it right now into a non-master branch, and then start doing some of my own work on top.

Thank you so much for all the hard work on this, @fritzherald! Your feedback on the design has really helped make this thing better. You rock.

@spenczar spenczar merged commit c1dacba into twitchtv:v6_streams_alpha Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants