I am writing a connection back to a TensorFlow Serving system with gRPC from a C# platform on MS Windows 10. I have seen many references to Time-out and Dead-line with the C++ API for gRPC, but can't seem to figure out how to for a timeout under C#.
I am simply opening a channel to the server, setting up a client and the calling to the server. I would like this Classify to time-out after 5 seconds or so. Any help or direction would be appreciated.
channel = new Channel(modelServer, ChannelCredentials.Insecure);
var client = MyService.NewClient(channel);
MyResponse classvalue = client.Classify(featureSet);
gRPC supports specifying a timeout for both client as well as the server. The Client can specify during runtime the amount of time it wants to wait before cancelling the request. The Server can also check on its end whether the requests need to be catered to or has the Client already given up on the request.
GRPC uses keepalive ping as a way to check if a channel is currently working by sending HTTP2 pings over the transport. It is sent periodically, and if the ping is not acknowledged by the peer within a certain timeout period, the transport is disconnected [1].
a blocking/synchronous stub: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception. a non-blocking/asynchronous stub that makes non-blocking calls to the server, where the response is returned asynchronously.
A deadline allows a gRPC client to specify how long it will wait for a call to complete. When a deadline is exceeded, the call is canceled. Setting a deadline is important because it provides an upper limit on how long a call can run for.
To set the deadline for a call, you can simply use the following "deadline:"
client.Classify(featureSet, deadline: DateTime.UtcNow.AddSeconds(5));
or
client.Classify(featureSet, new CallOptions(deadline: DateTime.UtcNow.AddSeconds(5)));
Both ways should be easily discoverable by code completion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With