I have created a sample gRPC client and server in golang (used protobufs). I understand the concurrency model in golang. However, I am trying to understand the concurrency model in a server accepting parallel requests from same client(multiple goroutines on client side)/ multiple clients.
More specifically:
grpcServer.Serve
set the boundary for data shared across goroutines i.e. everything set before is shared? (I am thinking of threads in Java where the threads share global data)When a new gRPC call comes, does server create a new goroutine?
Yes, and it's highly likely that it creates a lot of concurrent goroutines to handle every connection and request (especially streaming request).
What data is shared by these goroutines?
I think this question is too broad. There are too much code both in net/http2
and google.golang.org/grpc
packages to answer your question without deep investigation. However, we can be sure, that these goroutines share at least the server itself, because ServeConn
is not a free function, but a method defined on http2.Server
type.