When streaming is better than individual calls
So far, we have only had one RPC in our solution. This was a unary RPC, GetPerformance
, which is where we've been sending a single response message and retrieving a single request message. Having a unary RPC is acceptable in scenarios where it's only meant to be called occasionally.
However, we haven't been using it this way. We have been bombarding this endpoint with many repeated calls. And this is precisely the type of situation where a unary RPC is not the best tool for the job. A bi-directional streaming RPC would be a better option as it will improve our performance significantly.
Setting up a bi-directional streaming RPC
Let's open the performance.proto
file, which resides inside the Protos
folder of the GrpcDependencies
project. Now, add the following RPC to the Monitor
service
definition:
rpc GetManyPerformanceStats (stream PerformanceStatusRequest) returns (stream PerformanceStatusResponse...