containerd / ttrpc-rust

Rust implementation of ttrpc (GRPC for low-memory environments)
Apache License 2.0
195 stars 45 forks source link

Streaming support. #146

Closed wllenyj closed 2 years ago

wllenyj commented 2 years ago

Introduce support for streaming(https://github.com/containerd/ttrpc/blob/main/PROTOCOL.md#streaming). This is already supported by Golang's TTRPC in https://github.com/containerd/ttrpc/pull/107. But currently only async is implemented. Related issues #144.

This pull request changes include:

  1. Improved message encoding and decoding.
  2. Added shutdown module to handle graceful shutdown.
  3. Refactored connection handling.
  4. Added streaming support, and added an example about streaming.

Usually, streaming supports 3 types:

These 3 types are the same as GRPC, see https://grpc.io/docs/what-is-grpc/core-concepts/#server-streaming-rpc for details.

A general Bidirectional streaming process is as follows:

image

The Connection is an abstraction of a connection. One connection is handled as one Write async-task and one Read async-task.

Tim-Zhang commented 2 years ago

@wllenyj Awesome! Thanks a ton for introducing this so important feature. @jodh-intel @mxpv @lifupan @liubin Please take a look at this.

wllenyj commented 2 years ago

@dmcgowan Any time to help with this? Thanks a lot.

dmcgowan commented 2 years ago

@wllenyj thanks! I'll take a look

codecov[bot] commented 2 years ago

Codecov Report

Merging #146 (98d128d) into master (8f2bd91) will increase coverage by 14.34%. The diff coverage is 37.58%.

@@             Coverage Diff             @@
##           master     #146       +/-   ##
===========================================
+ Coverage   11.68%   26.02%   +14.34%     
===========================================
  Files          13       16        +3     
  Lines        1549     2413      +864     
===========================================
+ Hits          181      628      +447     
- Misses       1368     1785      +417     
Impacted Files Coverage Δ
src/asynchronous/client.rs 0.00% <0.00%> (ø)
src/asynchronous/connection.rs 0.00% <0.00%> (ø)
src/asynchronous/server.rs 0.00% <0.00%> (ø)
src/asynchronous/stream.rs 0.00% <0.00%> (ø)
src/asynchronous/utils.rs 0.00% <ø> (ø)
src/common.rs 34.57% <ø> (-14.76%) :arrow_down:
src/error.rs 55.55% <ø> (+55.55%) :arrow_up:
src/lib.rs 100.00% <ø> (ø)
src/sync/channel.rs 0.00% <ø> (ø)
src/sync/client.rs 0.00% <0.00%> (ø)
... and 8 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.