stream vs repeated

5,404 views
Skip to first unread message

Julien

unread,
Mar 31, 2017, 11:39:06 AM3/31/17
to grpc.io
Hello.

I need to get a list of messages from server to client.
I see two possible ways to implement this:
1.
  - define the message
  - define a service with a function which returns a stream of the message

2.  
  - define the message
  - define a second message with a repeated field of the first message
  - define a service with a function which returns the second message

Here is an example:

syntax = "proto3";

import "google/protobuf/empty.proto";

message
Dummy {
 
string foo = 1;
 
string bar = 2;
}

message
DummyList {
  repeated
Dummy dummy = 1;
}

service
DummyService {
  rpc getDummyListWithStream
(google.protobuf.Empty) returns (stream Dummy) {}
  rpc getDummyListWithRepeated
(google.protobuf.Empty) returns (DummyList) {}
}


What is the most efficient way to implement this? getDummyListWithStream or getDummyListWithRepeated?
Note: client and server are both written in C++.

Thanks.

Julien

Eric Gribkoff

unread,
Mar 31, 2017, 12:13:13 PM3/31/17
to Julien, grpc.io
There are tradeoffs with either approach. The repeated field approach is akin to batching, and requires all of the messages to be prepared by the server before any are sent, and the entire set of messages to be received by the client before doing any processing, increasing latency. On the other hand, if the repeated fields are highly compressible as a batch, sending them all as a single message will allow gRPC's per-message compression to reduce the message size (gRPC streaming compression is work in progress, and would allow the stream approach to also benefit from compression across multiple messages).

In general, if your use case would allow the client to process the incoming messages one at a time, the stream is the better choice. If your client will just be blocking until all of the messages arrive and then processing them in aggregate, the repeated field may be appropriate, but even in this scenario the stream would work just as well, except for losing some potential compressibility.

Eric

--
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.
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/b8e554c0-c1c3-4877-b1ad-082e1945ad83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julien

unread,
Mar 31, 2017, 12:34:13 PM3/31/17
to grpc.io, julien....@laposte.net
Hi Eric,

Thanks a lot for your reply.
I think that in our case the "repeated" solution would be fine because the client must have received all the data before processing them.

Julien
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