C++ server async read write multiplexing

613 views
Skip to first unread message

Arpit Baldeva

unread,
Feb 22, 2017, 7:45:36 PM2/22/17
to grpc.io
Hi,

For bi-directional streaming, can I have both pending read and write operations at the same time (1 of each)?

All the examples I found so far seem to do ping-pong behavior (1 read followed by 1 write) but I don't recall reading any documentation that mentions this constraint on protocol level. In other words, can I do multiple reads followed by a single write (and vice versa)? And if that is true, I'd like to be able to request both async read and write at the same time.

Thanks. 

Vijay Pai

unread,
Feb 22, 2017, 10:59:30 PM2/22/17
to Arpit Baldeva, grpc.io
You can have a simultaneous pending read and write operation on a stream in the C++ async API, no problem. Ping-pong is not required for any gRPC streaming operations.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/a8324087-4dcf-45c3-bd99-ca187b4cb993%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arpit Baldeva

unread,
Feb 22, 2017, 11:24:26 PM2/22/17
to Vijay Pai, grpc.io
Thanks for the info.

The documentation for  grpc::ServerAsyncReaderWriter< W, R >::Read says (http://www.grpc.io/grpc/cpp/classgrpc_1_1_server_async_reader_writer.html#a2adbae40645434ad5f55823967998acc ) -

It should not be called concurrently with other streaming APIs on the same stream. "

So if a streaming write operation is allowed concurrently, this doc should be updated? 

And then on the same topic, if I have a read operation queued but meanwhile the server decides to finish up (say an error/whatever), can I queue up a Finish/FinishWithError call? Or is the correct usage there is to call TryCancel on the server context with an AsyncNotifyWhenDone call?

Thanks. 



On Wed, Feb 22, 2017 at 7:59 PM, Vijay Pai <vp...@google.com> wrote:
You can have a simultaneous pending read and write operation on a stream in the C++ async API, no problem. Ping-pong is not required for any gRPC streaming operations.

On Wed, Feb 22, 2017 at 4:45 PM Arpit Baldeva <abal...@gmail.com> wrote:
Hi,

For bi-directional streaming, can I have both pending read and write operations at the same time (1 of each)?

All the examples I found so far seem to do ping-pong behavior (1 read followed by 1 write) but I don't recall reading any documentation that mentions this constraint on protocol level. In other words, can I do multiple reads followed by a single write (and vice versa)? And if that is true, I'd like to be able to request both async read and write at the same time.

Thanks. 

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

Vijay Pai

unread,
Feb 23, 2017, 12:05:50 AM2/23/17
to Arpit Baldeva, grpc.io
Please note the sentence before the one you quoted: "This is thread-safe with respect to Write or WritesDone methods. It should not be called concurrently with other streaming APIs on the same stream." By "other streaming APIs," I meant "other than Write or Writes Done," but I understand that it can be confusing so we can move to rewrite that comment.

If you need to finish up with an error while there is a read outstanding, you should do cancel/AsyncNotify as you mentioned. Finish isn't meant to be done concurrently with either Read or Write operations.

Regards,
Vijay

On Wed, Feb 22, 2017 at 8:24 PM Arpit Baldeva <abal...@gmail.com> wrote:
Thanks for the info.

The documentation for  grpc::ServerAsyncReaderWriter< W, R >::Read says (http://www.grpc.io/grpc/cpp/classgrpc_1_1_server_async_reader_writer.html#a2adbae40645434ad5f55823967998acc ) -

It should not be called concurrently with other streaming APIs on the same stream. "

So if a streaming write operation is allowed concurrently, this doc should be updated? 

And then on the same topic, if I have a read operation queued but meanwhile the server decides to finish up (say an error/whatever), can I queue up a Finish/FinishWithError call? Or is the correct usage there is to call TryCancel on the server context with an AsyncNotifyWhenDone call?

Thanks. 


On Wed, Feb 22, 2017 at 7:59 PM, Vijay Pai <vp...@google.com> wrote:
You can have a simultaneous pending read and write operation on a stream in the C++ async API, no problem. Ping-pong is not required for any gRPC streaming operations.

On Wed, Feb 22, 2017 at 4:45 PM Arpit Baldeva <abal...@gmail.com> wrote:
Hi,

For bi-directional streaming, can I have both pending read and write operations at the same time (1 of each)?

All the examples I found so far seem to do ping-pong behavior (1 read followed by 1 write) but I don't recall reading any documentation that mentions this constraint on protocol level. In other words, can I do multiple reads followed by a single write (and vice versa)? And if that is true, I'd like to be able to request both async read and write at the same time.

Thanks. 

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages