C++ async streaming with multiple clients and wait for data

428 views
Skip to first unread message

shashank shekhar

unread,
Jun 18, 2021, 10:07:45 AM6/18/21
to grpc.io
Hi,

We have a use-case where there is one async streaming server sending messages to multiple clients in round-robin fashion. The data is not always available and need to wait for the producer to generate data before it can be sent out. 

We followed the suggestions provided in the below article to overcome the behavior of task being added to the front of the completion queue and using alarms to wait for the producer -


However, the approach is not elegant and adds the overhead of alarm tasks. Is this the suggested approach for async streaming or is there an alternative that we are missing?

Thanks in advance for your response.


Jeff Steger

unread,
Jun 18, 2021, 10:29:57 AM6/18/21
to shashank shekhar, grpc.io
Great question. I too encountered the same limitation and solved it using the same article. But the fact that grpc doesnt natively support this is def a shortcoming imo. thanks for posting this. 

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/b40e1303-cfbd-4ccb-8524-d7c1e4edf2e4n%40googlegroups.com.

Christopher Pisz

unread,
Jul 1, 2021, 3:45:28 PM7/1/21
to grpc.io
Wait wait...you implemented a GRPC asynch bidirectional streaming server in C++?
I've been looking for 6 months for one that actually works and doesn't block. Can I see? Can I see?

Jeff Steger

unread,
Jul 1, 2021, 8:16:57 PM7/1/21
to Christopher Pisz, grpc.io
I implemented a grpc async streaming server that processes single requests (ie the streaming is not bidirectional). But you should be able to modify it so that it can process streaming requests. Here she is:



--
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.

Jeff Steger

unread,
Jul 1, 2021, 8:40:16 PM7/1/21
to Christopher Pisz, grpc.io
its been a while since i looked at that code but it seems like a good place for you to tinker with is in the section that defines async writers:


// write for single request, streaming response
template <class Reply>
using AsyncStreamingWriter = grpc::ServerAsyncWriter<Reply>;
// Writer for request/response one-shots
template <class Reply>
using AsyncStandardWriter = grpc::ServerAsyncResponseWriter<Reply>;

Reply all
Reply to author
Forward
0 new messages