grpc-go icon indicating copy to clipboard operation
grpc-go copied to clipboard

Concurrency

Open rubenv opened this issue 11 years ago • 7 comments

How does grpc handle concurrency? Can I use a client from different threads in parallel?

rubenv avatar Feb 27 '15 17:02 rubenv

On Fri, Feb 27, 2015 at 9:40 AM, Ruben Vermeersch [email protected] wrote:

How does grpc handle concurrency? Can I use a client from different threads in parallel?

On client, if you want to perform multiple rpc in parallel, you should spawn multiple goroutines to do that since the rpc is synchronous/blocking.

— Reply to this email directly or view it on GitHub https://github.com/grpc/grpc-go/issues/85.

iamqizhao avatar Feb 27 '15 19:02 iamqizhao

since the rpc is synchronous/blocking

That's what I got from looking at the route_guide example: the server's end points access a slice without locks. Is this considered quasi similar to an actor model? Is there documentation about this fact (I might have missed it)?

jpfuentes2 avatar Feb 27 '15 19:02 jpfuentes2

On Fri, Feb 27, 2015 at 11:27 AM, Jacques Fuentes [email protected] wrote:

since the rpc is synchronous/blocking

That's what I got from looking at the route_guide example: the server's end points access a slice without locks. Is this considered quasi similar to an actor model? Is there documentation about this fact (I might have missed it)?

To be clear, I was talking about client side. On the server side, each rpc still has its own goroutine but the concurrency is model is different -- the goroutine is spawned by grpc internals instead of applications.

Were you talking about "savedFeatures" slice? There is no lock for that because it is read-only once it is initialized (in grpc.NewServer).

— Reply to this email directly or view it on GitHub https://github.com/grpc/grpc-go/issues/85#issuecomment-76455866.

iamqizhao avatar Feb 27 '15 21:02 iamqizhao

There is no lock for that because it is read-only once it is initialized

Got it, thanks.

jpfuentes2 avatar Feb 27 '15 21:02 jpfuentes2

I also wasn't able to find this documented anywhere but this issue. Would you be able to add this to the godoc documentation to make it more clear that it's safe to call a client from multiple go routines concurrently?

trevorgray avatar Oct 17 '15 20:10 trevorgray

Trying to summarize for myself...

@rubenv asks:

Can I use a client from different threads in parallel?

@iamqizhao replies:

On client, if you want to perform multiple rpc in parallel, you should spawn multiple goroutines to do that since the rpc is synchronous/blocking

That's helpful, thanks, but doesn't quite clarify if a single client object can be used by all those "multiple goroutines". It sounds like the answer is yes. This example suggests the same. Is that right?

However, a stream can't be shared.

@trevorgray, these kinds of concurrency topics are apparently still not documented, per #682.

timbunce avatar Jun 30 '17 12:06 timbunce

That's helpful, thanks, but doesn't quite clarify if a single client object can be used by all those "multiple goroutines". It sounds like the answer is yes. This example suggests the same. Is that right?

However, a stream can't be shared.

That all sounds right to me.

@trevorgray, these kinds of concurrency topics are apparently still not documented, per #682.

Documentation is a well-known deficiency that I hope to address sometime this quarter.

dfawley avatar Jul 05 '17 18:07 dfawley