Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are channel/stubs in gRPC thread-safe

When using gRPC from Java, can I cache stubs (clients) and call them in a multi-threaded environment or are the channels thread-safe and can be safely cached?

If there is a network outage, should I recreate the channel or it is smart enough to reconnect? I couldn't find relevant info on http://www.grpc.io/docs/

Thanks

like image 855
julius Avatar asked Oct 18 '15 11:10

julius


1 Answers

Answer to first question:

Channels are thread safe; io.grpc.Channel is marked with @ThreadSafe annotation. Stubs are also thread-safe, which is why reconfiguration creates a new stub.

Answer to second question:

If there is a network outage, you don't need to recreate the channel. The channel will reconnect with exponential backoff, roughly as described by the connection backoff doc. Java does not 100% conform to that algorithm, because it doesn't increase connection timeouts in later retries. (Not to be confused with the exponential backoff, which is implemented.)

like image 193
Eric Anderson Avatar answered Sep 18 '22 21:09

Eric Anderson